QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#595358 | #9419. Normal Friends | ucup-team5075# | WA | 1ms | 5964kb | C++14 | 1.6kb | 2024-09-28 13:31:57 | 2024-09-28 13:31:58 |
Judging History
answer
#include<iostream>
#include<cstdio>
using namespace std;
const int N=3e5+9;
int son[N<<2][20],siz[N];
int tag[N<<2];
int ncnt=1,rt=1;
void build(int &u,int l,int r)
{
// cerr<<"build "<<l<<" "<<r<<endl;
if(!u) u=++ncnt;
if(l==r) return siz[u]=1,void();
int mid;
scanf("%d",&mid);
build(son[u][0],l,mid);
build(son[u][1],mid+1,r);
siz[u]=siz[son[u][0]]+siz[son[u][1]];
}
void rev(int u)
{
swap(son[u][0],son[u][1]);
tag[u]^=1;
}
void pushdown(int u)
{
if(tag[u])
{
rev(son[u][0]);
rev(son[u][1]);
tag[u]=0;
}
}
void pushup(int u)
{
siz[u]=siz[son[u][0]]+siz[son[u][1]];
}
int pos[N];
int id0[N];
void Modify1(int u,int l,int r,int L,int R)
{
// cerr<<"Modify1 "<<u<<" "<<l<<" "<<r<<" "<<L<<" "<<R<<endl;
if(L<=l&&r<=R) return pos[++pos[0]]=u,tag[u]^=1,void();
pushdown(u);
int Mid=l+siz[son[u][0]]-1;
if(L<=Mid) Modify1(son[u][0],l,Mid,L,R);
if(Mid<R) Modify1(son[u][1],Mid+1,r,L,R);
}
void Modify2(int u,int l,int r,int L,int R)
{
if(r<L||R<l) return;
pushdown(u);
int mid=l+siz[son[u][0]]-1;
if(id0[son[u][0]]) son[u][0]=id0[son[u][0]];
else Modify2(son[u][0],l,mid,L,R);
if(id0[son[u][1]]) son[u][1]=id0[son[u][1]];
else Modify2(son[u][1],mid+1,r,L,R);
pushup(u);
}
int n,Q;
signed main()
{
scanf("%d%d",&n,&Q);
build(rt,1,n);
// cerr<<"ended.\n";
while(Q--)
{
int r;
scanf("%d",&r);
Modify1(rt,1,n,1,r);
int k=pos[0];
printf("%d\n",k);
for(int i=1;i<=k;i++) id0[pos[k-i+1]]=pos[i];
if(pos[1]!=1) Modify2(rt,1,n,1,r);
for(int i=1;i<=k;i++) id0[pos[i]]=0;
pos[0]=0;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5964kb
input:
3 3 2 1 2 3 2
output:
1 1 1
result:
wrong answer 3rd numbers differ - expected: '2', found: '1'