Submission #1097747

# Submission time Handle Problem Language Result Execution time Memory
1097747 2024-10-08T07:03:15 Z vjudge1 Inside information (BOI21_servers) C++14
100 / 100
349 ms 55380 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN=3e5+10;
struct node{
    int ls,rs,sum;
}tr[MAXN*400];
int tot=0;
int rt[MAXN],xi[MAXN],yi[MAXN];
char tim[MAXN];
bool ans[MAXN];
void pushup(int x){
    int l=tr[x].ls,r=tr[x].rs;
    tr[x].sum=tr[l].sum+tr[r].sum;
    //cout<<tr[x].sum<<endl;
}
int clone(int x){
    tr[++tot]=tr[x];
    return tot;
}
void modify(int pre,int &v,int l,int r,int x,int k){
	v=clone(pre);
	if(l==r){
		tr[v].sum+=k;
		return ;
	}
	int mid=(l+r)>>1;
	if(x<=mid)modify(tr[pre].ls,tr[v].ls,l,mid,x,k);
	else modify(tr[pre].rs,tr[v].rs,mid+1,r,x,k); 
	pushup(v);
}
int merge(int x,int y,int l,int r){
    if(!x)return y;
    if(!y)return x;
    int nd=clone(0);
    if(l==r){
        tr[nd].sum=tr[x].sum+tr[y].sum;
        return nd;
    }
    int mid=(l+r)/2;
    tr[nd].ls=merge(tr[x].ls,tr[y].ls,l,mid);
    tr[nd].rs=merge(tr[x].rs,tr[y].rs,mid+1,r);
    pushup(nd);
    return nd;
}
int query(int x,int l,int r,int pos){
    if(l==r)return tr[x].sum;
    int mid=(l+r)/2;
    if(pos<=mid)return query(tr[x].ls,l,mid,pos);
    else return query(tr[x].rs,mid+1,r,pos);
}
int qsum(int x,int l,int r,int L,int R){
    if(L<=l&&R>=r){
        return tr[x].sum;
    }
    if(l>R||r<L)return 0;
    if(l>r)return 0;
    if(!x)return 0;
    int mid=(l+r)/2;
    int sum=0;
    sum+=qsum(tr[x].ls,l,mid,L,R);
    sum+=qsum(tr[x].rs,mid+1,r,L,R);
    return sum;
}
int main(){
    ios::sync_with_stdio(0);
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++){
        modify(rt[0],rt[i],1,n,i,1);
    }

    for(int i=1;i<=n+m-1;i++){
        char str;
        cin>>str;tim[i]=str;
        if(str=='S'){
            cin>>xi[i]>>yi[i];
            
            rt[xi[i]]=merge(rt[xi[i]],rt[yi[i]],1,n);
            rt[yi[i]]=rt[xi[i]];
            
        }else if(str=='Q'){
            cin>>xi[i]>>yi[i];
            ans[i]=query(rt[xi[i]],1,n,yi[i]);
        }else{
            cin>>xi[i];
        }
    }
    for(int i=0;i<=tot;i++)tr[i]={0,0,0};
    tot=0;
    memset(rt,0,sizeof rt);
    for(int i=1;i<=n;i++)rt[i]=++tot;
    for(int i=n+m-1;i>=1;i--){
        if(tim[i]=='S'){
            modify(rt[xi[i]],rt[xi[i]],1,n+m-1,i,1);
            rt[xi[i]]=merge(rt[xi[i]],rt[yi[i]],1,n+m-1);
            rt[yi[i]]=rt[xi[i]];
            //cout<<rt[xi[i]]<<endl;
        }
    }

    for(int i=1;i<=n+m-1;i++){
        if(tim[i]=='Q'){
            if(ans[i])cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }else if(tim[i]=='C'){
            cout<<(qsum(rt[xi[i]],1,n+m-1,1,i)+1)<<endl;
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 127 ms 3920 KB Output is correct
2 Correct 152 ms 5460 KB Output is correct
3 Correct 145 ms 5716 KB Output is correct
4 Correct 137 ms 5460 KB Output is correct
5 Correct 140 ms 5652 KB Output is correct
6 Correct 146 ms 5788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 3920 KB Output is correct
2 Correct 152 ms 5460 KB Output is correct
3 Correct 145 ms 5716 KB Output is correct
4 Correct 137 ms 5460 KB Output is correct
5 Correct 140 ms 5652 KB Output is correct
6 Correct 146 ms 5788 KB Output is correct
7 Correct 131 ms 3920 KB Output is correct
8 Correct 150 ms 5084 KB Output is correct
9 Correct 142 ms 5708 KB Output is correct
10 Correct 137 ms 5036 KB Output is correct
11 Correct 136 ms 5200 KB Output is correct
12 Correct 150 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 3928 KB Output is correct
2 Correct 319 ms 54680 KB Output is correct
3 Correct 330 ms 54868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 3928 KB Output is correct
2 Correct 319 ms 54680 KB Output is correct
3 Correct 330 ms 54868 KB Output is correct
4 Correct 129 ms 3928 KB Output is correct
5 Correct 332 ms 54740 KB Output is correct
6 Correct 289 ms 53584 KB Output is correct
7 Correct 286 ms 54096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 4052 KB Output is correct
2 Correct 283 ms 55380 KB Output is correct
3 Correct 264 ms 55376 KB Output is correct
4 Correct 222 ms 55124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 4052 KB Output is correct
2 Correct 283 ms 55380 KB Output is correct
3 Correct 264 ms 55376 KB Output is correct
4 Correct 222 ms 55124 KB Output is correct
5 Correct 128 ms 3924 KB Output is correct
6 Correct 271 ms 54868 KB Output is correct
7 Correct 249 ms 54860 KB Output is correct
8 Correct 275 ms 54516 KB Output is correct
9 Correct 286 ms 54356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 4040 KB Output is correct
2 Correct 246 ms 51860 KB Output is correct
3 Correct 312 ms 48212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 4040 KB Output is correct
2 Correct 246 ms 51860 KB Output is correct
3 Correct 312 ms 48212 KB Output is correct
4 Correct 127 ms 3924 KB Output is correct
5 Correct 260 ms 51540 KB Output is correct
6 Correct 289 ms 47952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 3920 KB Output is correct
2 Correct 274 ms 55348 KB Output is correct
3 Correct 273 ms 55380 KB Output is correct
4 Correct 249 ms 55124 KB Output is correct
5 Correct 126 ms 3924 KB Output is correct
6 Correct 253 ms 51796 KB Output is correct
7 Correct 285 ms 48256 KB Output is correct
8 Correct 258 ms 40400 KB Output is correct
9 Correct 255 ms 39860 KB Output is correct
10 Correct 300 ms 55312 KB Output is correct
11 Correct 308 ms 55376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 3920 KB Output is correct
2 Correct 274 ms 55348 KB Output is correct
3 Correct 273 ms 55380 KB Output is correct
4 Correct 249 ms 55124 KB Output is correct
5 Correct 126 ms 3924 KB Output is correct
6 Correct 253 ms 51796 KB Output is correct
7 Correct 285 ms 48256 KB Output is correct
8 Correct 258 ms 40400 KB Output is correct
9 Correct 255 ms 39860 KB Output is correct
10 Correct 300 ms 55312 KB Output is correct
11 Correct 308 ms 55376 KB Output is correct
12 Correct 137 ms 4224 KB Output is correct
13 Correct 288 ms 54868 KB Output is correct
14 Correct 244 ms 54840 KB Output is correct
15 Correct 282 ms 54352 KB Output is correct
16 Correct 282 ms 54356 KB Output is correct
17 Correct 134 ms 3920 KB Output is correct
18 Correct 272 ms 51540 KB Output is correct
19 Correct 291 ms 47952 KB Output is correct
20 Correct 266 ms 40020 KB Output is correct
21 Correct 279 ms 39432 KB Output is correct
22 Correct 302 ms 54636 KB Output is correct
23 Correct 316 ms 53588 KB Output is correct
24 Correct 322 ms 54100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 4068 KB Output is correct
2 Correct 149 ms 5576 KB Output is correct
3 Correct 147 ms 5716 KB Output is correct
4 Correct 138 ms 5572 KB Output is correct
5 Correct 137 ms 5716 KB Output is correct
6 Correct 144 ms 5848 KB Output is correct
7 Correct 136 ms 4080 KB Output is correct
8 Correct 326 ms 54672 KB Output is correct
9 Correct 323 ms 54608 KB Output is correct
10 Correct 129 ms 3856 KB Output is correct
11 Correct 287 ms 54668 KB Output is correct
12 Correct 280 ms 54672 KB Output is correct
13 Correct 238 ms 54864 KB Output is correct
14 Correct 128 ms 3924 KB Output is correct
15 Correct 251 ms 51316 KB Output is correct
16 Correct 284 ms 47956 KB Output is correct
17 Correct 258 ms 40020 KB Output is correct
18 Correct 247 ms 39484 KB Output is correct
19 Correct 274 ms 55016 KB Output is correct
20 Correct 284 ms 54864 KB Output is correct
21 Correct 303 ms 54868 KB Output is correct
22 Correct 304 ms 54868 KB Output is correct
23 Correct 266 ms 47188 KB Output is correct
24 Correct 294 ms 47184 KB Output is correct
25 Correct 283 ms 45144 KB Output is correct
26 Correct 287 ms 52716 KB Output is correct
27 Correct 285 ms 54736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 4068 KB Output is correct
2 Correct 149 ms 5576 KB Output is correct
3 Correct 147 ms 5716 KB Output is correct
4 Correct 138 ms 5572 KB Output is correct
5 Correct 137 ms 5716 KB Output is correct
6 Correct 144 ms 5848 KB Output is correct
7 Correct 136 ms 4080 KB Output is correct
8 Correct 326 ms 54672 KB Output is correct
9 Correct 323 ms 54608 KB Output is correct
10 Correct 129 ms 3856 KB Output is correct
11 Correct 287 ms 54668 KB Output is correct
12 Correct 280 ms 54672 KB Output is correct
13 Correct 238 ms 54864 KB Output is correct
14 Correct 128 ms 3924 KB Output is correct
15 Correct 251 ms 51316 KB Output is correct
16 Correct 284 ms 47956 KB Output is correct
17 Correct 258 ms 40020 KB Output is correct
18 Correct 247 ms 39484 KB Output is correct
19 Correct 274 ms 55016 KB Output is correct
20 Correct 284 ms 54864 KB Output is correct
21 Correct 303 ms 54868 KB Output is correct
22 Correct 304 ms 54868 KB Output is correct
23 Correct 266 ms 47188 KB Output is correct
24 Correct 294 ms 47184 KB Output is correct
25 Correct 283 ms 45144 KB Output is correct
26 Correct 287 ms 52716 KB Output is correct
27 Correct 285 ms 54736 KB Output is correct
28 Correct 131 ms 3920 KB Output is correct
29 Correct 139 ms 5260 KB Output is correct
30 Correct 139 ms 5456 KB Output is correct
31 Correct 138 ms 5108 KB Output is correct
32 Correct 137 ms 5196 KB Output is correct
33 Correct 157 ms 5452 KB Output is correct
34 Correct 127 ms 4036 KB Output is correct
35 Correct 306 ms 54356 KB Output is correct
36 Correct 285 ms 53588 KB Output is correct
37 Correct 278 ms 53844 KB Output is correct
38 Correct 133 ms 3928 KB Output is correct
39 Correct 290 ms 54356 KB Output is correct
40 Correct 248 ms 54552 KB Output is correct
41 Correct 295 ms 54096 KB Output is correct
42 Correct 258 ms 54100 KB Output is correct
43 Correct 126 ms 3924 KB Output is correct
44 Correct 267 ms 51024 KB Output is correct
45 Correct 271 ms 47556 KB Output is correct
46 Correct 268 ms 39548 KB Output is correct
47 Correct 265 ms 39136 KB Output is correct
48 Correct 306 ms 54340 KB Output is correct
49 Correct 349 ms 53072 KB Output is correct
50 Correct 322 ms 54116 KB Output is correct
51 Correct 287 ms 54220 KB Output is correct
52 Correct 296 ms 54612 KB Output is correct
53 Correct 282 ms 54096 KB Output is correct
54 Correct 286 ms 54452 KB Output is correct
55 Correct 298 ms 54232 KB Output is correct
56 Correct 273 ms 46680 KB Output is correct
57 Correct 285 ms 44884 KB Output is correct
58 Correct 291 ms 48724 KB Output is correct
59 Correct 309 ms 54572 KB Output is correct