QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#525520 | #990. Colorful Components | lefy | WA | 11ms | 149632kb | C++14 | 2.8kb | 2024-08-20 17:30:58 | 2024-08-20 17:30:58 |
Judging History
answer
#include <bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define ll long long
using namespace std;
const int M=3e6+10,N=5e5+10;
int T,n;
int getid(int las,int x){
return (x-1+(ll)T*las%n)%n+1;
}
int tr[N<<2];
void pushup(int rt){
tr[rt]=tr[ls]+tr[rs];
}
void update(int rt,int l,int r,int p,int val){
if(l==r){
tr[rt]=val;return;
}
int mid=l+r>>1;
if(mid>=p)update(ls,l,mid,p,val);
else update(rs,mid+1,r,p,val);
pushup(rt);
}
void bd(int rt,int l,int r){
tr[rt]=r-l+1;
if(l==r)return;
int mid=l+r>>1;
bd(ls,l,mid),bd(rs,mid+1,r);
}
int q(int rt,int l,int r,int L,int R){
if(!tr[rt])return 1e9;
int mid=l+r>>1;
if(L<=l&&r<=R){
if(l==r)return l;
int ans=q(ls,l,mid,L,R);
if(ans!=1e9)return ans;
return q(rs,mid+1,r,L,R);
}
if(R<=mid)return q(ls,l,mid,L,R);
if(mid<L)return q(rs,mid+1,r,L,R);
int ans=q(ls,l,mid,L,R);
if(ans!=1e9)return ans;
return q(rs,mid+1,r,L,R);
}
int getans(int x){
if(!tr[1])return 0;
int ans=q(1,1,n,x,n);
if(ans!=1e9)return ans;
return q(1,1,n,1,x-1);
}
int vis[M],tag[M],tot[M],poi[M];
vector<pair<int,int> >e[M];
queue<int>qu;
vector<int>to[M];
void del(int x){
if(vis[x])return;
vis[x]=1;
for(int v:to[x]){
tot[v]++;
if(tot[v]==e[v].size())del(v);
}
for(auto u:e[x]){
if(x==tag[poi[u.first]])update(1,1,n,u.first,0);
qu.push(u.second);
}
}
int m;
void add(int x){
qu.push(x);
while(!qu.empty()){
x=qu.front();qu.pop();
if(tag[x])
del(tag[x]);
}
}
char ch[10];
int main() {
// freopen("array3.in","r",stdin);
// freopen("3.out","w",stdout);
scanf("%d%d%d",&n,&m,&T);
bd(1,1,n);int lasans=0;
int idd=m+n;
for(int i=1;i<=n;i++)tag[poi[i]=++idd]=i,e[i].push_back({i,0});
for(int i=n+1;i<=m+n;i++){
scanf("%s",ch+1);
if(ch[1]=='Q'){
int x;scanf("%d",&x);x=getid(lasans,x);
lasans=getans(x);
if(!lasans)printf("YES\n");
else printf("NO %d\n",lasans);
}else if(ch[1]=='M'){
int k;scanf("%d",&k);
int K=k;
while(K--){
int x;scanf("%d",&x);x=getid(lasans,x);
tot[i]+=vis[tag[poi[x]]];
if(!vis[tag[poi[x]]])to[tag[poi[x]]].push_back(i);
e[i].push_back({x,poi[x]});
}
if(tot[i]!=k)for(auto x:e[i])update(1,1,n,x.first,1);
else vis[i]=1;
for(auto x:e[i])tag[poi[x.first]=++idd]=i;
}else{
int x,y;
scanf("%d%d",&x,&y);
x=getid(lasans,x);
if(y)update(1,1,n,x,0);
else add(poi[x]);
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 149632kb
input:
5 3 1 1 3 1 5
output:
result:
wrong answer Unexpected EOF in the participants output