WY模拟赛12

WY模拟赛12

T1. 洛谷 P10734 [NOISG 2019 Prelim] Experimental Charges

原题

扩展域并查集板子……。

code:


#include <bits/stdc++.h> 
#define i8  __int128
#define int long long 
#define fuck inline
#define lb long double 
using namespace std; 
// typedef long long ll; 
const int N=1e5+5,M=64,mod=998244353;
const int inf=INT_MAX,INF=1e9+7; 
// const int mod1=469762049,mod2=998244353,mod3=1004535809;
// const int G=3,Gi=332748118; 
// const int M=mod1*mod2;
fuck int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=getchar();}
    return x*f;
}
fuck void write(int x)
{
    if(x<0){putchar('-');x=-x;}
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
int n,q;
int fa[N+N];
fuck int findx(int x){return x==fa[x]?x:fa[x]=findx(fa[x]);}
fuck void solve()
{
    cin>>n>>q;
    for(int i=1;i<=2*n;i++)fa[i]=i;
    while(q--)
    {
        int x,y;char c;
        cin>>c>>x>>y;
        if(c=='Q')
        {
            if(findx(x)==findx(y)||findx(x+n)==findx(y+n))cout<<"R"<<"\n";
            else if(findx(x)==findx(y+n)||findx(y)==findx(x+n))cout<<"A"<<"\n";
            else cout<<"?"<<"\n";
        }
        if(c=='A')
        {
            fa[findx(y)]=fa[findx(x+n)];
            fa[findx(x)]=fa[findx(n+y)];
        }
        if(c=='R')
        {
            fa[findx(x)]=fa[findx(y)];
            fa[findx(x+n)]=fa[findx(y+n)];
        }
    }
}
signed main() 
{ 
    // ios::sync_with_stdio(false); 
    // cin.tie(0); cout.tie(0); 
    // int fuckccf=read();
    // int QwQ=read();
    // while(QwQ--)solve(); 
    solve(); 
    return 0; 
}
//  6666   66666  666666 
// 6    6  6   6      6 
// 6    6  6666      6 
// 6    6  6  6    6 
//  6666   6   6  6666666



T2. 洛谷 P12882 [蓝桥杯 2025 国 C] 数列染色

原题

单调队列优化DP……。

#include <bits/stdc++.h> 
#define i8  __int128
#define int long long 
#define fuck inline
#define lb long double 
using namespace std; 
// typedef long long ll; 
const int N=1e6+5,M=64,mod=1e9+7;
const int INF=1e9+7,inv2=5e8+4; 
const int inf=LONG_LONG_MAX/4;
// const int mod1=469762049,mod2=998244353,mod3=1004535809;
// const int G=3,Gi=332748118; 
// const int M=mod1*mod2;
fuck int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=getchar();}
    return x*f;
}
fuck void write(int x)
{
    if(x<0){putchar('-');x=-x;}
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
int n,k,a[N],f[N];
deque<int>q;
fuck void solve()
{
   cin>>n>>k;
   for(int i=1;i<=n;i++)cin>>a[i];
   f[1]=a[1];q.push_back(1);
   for(int i=2;i<=n;i++)
   {
      while(!q.empty()&&i-k-1>q.front())q.pop_front();
      f[i]=f[q.front()]+a[i];
      while(!q.empty()&&f[q.back()]>=f[i])q.pop_back();
      q.push_back(i);
   }
   cout<<f[n]<<"\n";
}
signed main() 
{ 
    // ios::sync_with_stdio(false); 
    // cin.tie(0); cout.tie(0); 
    // int QwQ=read();
    // int fuckccf=read();
    // while(QwQ--)solve(); 
    solve(); 
    return 0; 
}
//  6666   66666  666666 
// 6    6  6   6      6 
// 6    6  6666      6 
// 6    6  6  6    6 
//  6666   6   6  6666666


T3. 洛谷 P11289 【MX-S6-T1】「KDOI-11」打印

原题

维护两个优先队列,一个是工作的,一个是闲置的,结束时间早,编号小的放在前面,然后模拟即可。

#include <bits/stdc++.h> 
#define i8  __int128
#define int long long 
#define fuck inline
#define lb long double 
using namespace std; 
// typedef long long ll; 
const int N=2e5+5,M=64,mod=998244353;
const int inf=INT_MAX,INF=1e9+7; 
// const int mod1=469762049,mod2=998244353,mod3=1004535809;
// const int G=3,Gi=332748118; 
// const int M=mod1*mod2;
fuck int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=getchar();}
    return x*f;
}
fuck void write(int x)
{
    if(x<0){putchar('-');x=-x;}
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
int n,m;
priority_queue<int>q[N];
struct node
{
    int s,t,id;
    bool operator <(const node &a)const
    {
        return t<a.t;
    }
}p[N];
struct edge
{
   int now,id;
   bool operator <(const edge &a)const
   {
      if(now==a.now)return id>a.id;
      else return now>a.now;
   }
};
priority_queue<edge>qq,qqq;
fuck void solve()
{
   cin>>n>>m;
   for(int i=1;i<=n;i++)cin>>p[i].s>>p[i].t,p[i].id=i;
   sort(p+1,p+n+1);
   for(int i=1;i<=m;i++)qqq.push({0,i});
   for(int i=1;i<=n;i++)
   {
      while(!qq.empty()&&qq.top().now<=p[i].t)
      {
         qqq.push({0,qq.top().id});
         qq.pop();
      }
      if(!qqq.empty())
      {
         q[qqq.top().id].push(-p[i].id);
         qq.push({p[i].t+p[i].s,qqq.top().id});
         qqq.pop();
      }
      else
      {
         q[qq.top().id].push(-p[i].id);
         qq.push({qq.top().now+p[i].s,qq.top().id});
         qq.pop();
      }
   }
   for(int i=1;i<=m;i++)
   {
      cout<<q[i].size()<<" ";
      while(!q[i].empty())cout<<abs(q[i].top())<<" ",q[i].pop();
      cout<<"\n";
   }
    
}
signed main() 
{ 
    // ios::sync_with_stdio(false); 
    // cin.tie(0); cout.tie(0); 
    // int fuckccf=read();
    // int QwQ=read();
    // while(QwQ--)solve(); 
    solve(); 
    return 0; 
}
//  6666   66666  666666 
// 6    6  6   6      6 
// 6    6  6666      6 
// 6    6  6  6    6 
//  6666   6   6  6666666



T4. 洛谷 P12271 [蓝桥杯 2024 国 Python B] 括号与字母

原题

经典用栈维护括号对,然后在维护的同时非常神秘得计算各种字符的信息。

code:

#include <bits/stdc++.h> 
#define i8  __int128
// #define int long long 
#define fuck inline
#define lb long double 
using namespace std; 
typedef long long ll; 
const int N=1e6+5,M=64,mod=536870912;
const int INF=1e9+7; 
const ll inf=LONG_LONG_MAX/4;
// const int mod1=469762049,mod2=998244353,mod3=1004535809;
// const int G=3,Gi=332748118; 
// const int M=mod1*mod2;
fuck int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=getchar();}
    return x*f;
}
fuck void write(int x)
{
    if(x<0){putchar('-');x=-x;}
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
int n,q,sum[30][N],cnt[30][N];
stack<int>st;
fuck void solve()
{
   string s;cin>>s>>q;
   s=' '+s;
   for(int i=1;i<s.size();i++)
   {
      for(int j=0;j<26;j++)cnt[j][i]=cnt[j][i-1]+(s[i]==(j+'a'));
      if(s[i]=='(')st.push(i);
      if(s[i]==')')
      {
         for(int j=0;j<26;j++)sum[j][cnt[j][i]-cnt[j][st.top()-1]]++;
         st.pop();
      }
   }
   for(int j=0;j<26;j++)
      for(int i=s.size()-1;i>=0;i--)sum[j][i]+=sum[j][i+1];
   while(q--)
   {
      char c;int x;cin>>c>>x;
      cout<<sum[c-'a'][x]<<"\n";
   }
   
}
signed main() 
{ 
    // ios::sync_with_stdio(false); 
    // cin.tie(0); cout.tie(0); 
    // int QwQ=read();
    // int fuckccf=read();
    // while(QwQ--)solve(); 
    solve(); 
    return 0; 
}
//  6666   66666  666666 
// 6    6  6   6      6 
// 6    6  6666      6 
// 6    6  6  6    6 
//  6666   6   6  6666666


总结

  1. 该打暴力还是得好好打暴力;
  2. 常用的板子和算法还需多加练习;

完结收工!!!!!

个人主页

看完点赞,养成习惯

\(\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\)

posted @ 2025-07-18 23:07  Nightmares_oi  阅读(7)  评论(0)    收藏  举报