Submission #837968

# Submission time Handle Problem Language Result Execution time Memory
837968 2023-08-26T01:16:34 Z 1075508020060209tc Joker (BOI20_joker) C++14
49 / 100
2000 ms 13936 KB
#include <bits/stdc++.h>
using namespace std;
int n;int m;int Q;
int ar[400005];
int br[400005];
int uf[200005];
int isbip;
int sz[200005];
int ufv[200005];
stack<int>stk;
stack<int>stkv;
stack<int>stkbp;
int fin(int x){
if(uf[x]==x){return x;}
return fin(uf[x]);
}
int finv(int x){
if(uf[x]==x){return 0;}
return (ufv[x]+finv(uf[x]))%2;
}
void mrg(int a,int b){
int pa=fin(a);int pb=fin(b);
if(pa==pb){
    stk.push(0);stkbp.push(isbip);
    if(finv(a)==finv(b)){
        isbip=0;
    }
    return;
}
stkbp.push(isbip);
if(sz[pa]<sz[pb]){swap(pa,pb);swap(a,b);}
int va=finv(a);int vb=finv(b);
if(va==vb){
   // stkv.push(1);
    ufv[pb]=1;
    uf[pb]=pa;
    sz[pa]+=sz[pb];
}else{
    //stkv.push(0);
    ufv[pb]=0;
    uf[pb]=pa;
    sz[pa]+=sz[pb];
}
stk.push(pb);
}
void rollback(){
int pb=stk.top();
if(pb==0){
    stk.pop();//stkv.pop();
    isbip=stkbp.top();
    stkbp.pop();
    return;
}
isbip=stkbp.top();
stk.pop();stkbp.pop();
int pa=uf[pb];
sz[pa]-=sz[pb];
uf[pb]=pb;
ufv[pb]=0;
}
int lar[200005];int rar[200005];int lpl[200005];

void precalc(){
for(int i=1;i<=n;i++){
    uf[i]=i;
    ufv[i]=0;
    sz[i]=1;
}
while(stk.size()){stk.pop();}
while(stkbp.size()){stkbp.pop();}

}

void dolid(int lid){
precalc();
isbip=1;
lpl[lid]=0;
for(int i=m+lid-1;i>=lid-1;i--){
    mrg(ar[i],br[i]);
    if(!isbip){
        lpl[lid]=i;break;
    }
}
}

signed main(){
cin>>n>>m>>Q;
for(int i=1;i<=m;i++){
    cin>>ar[i]>>br[i];
    ar[i+m]=ar[i];
    br[i+m]=br[i];
}
set<int>st;
for(int i=1;i<=Q;i++){
    cin>>lar[i]>>rar[i];
    st.insert(lar[i]);
}
for(auto it=st.begin();it!=st.end();it++){
    int v=*it;
    dolid(v);
}
for(int i=1;i<=Q;i++){
    if(rar[i]<lpl[lar[i]]){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
}

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 14 ms 480 KB Output is correct
30 Correct 19 ms 508 KB Output is correct
31 Correct 17 ms 512 KB Output is correct
32 Correct 12 ms 468 KB Output is correct
33 Correct 7 ms 500 KB Output is correct
34 Correct 19 ms 468 KB Output is correct
35 Correct 21 ms 528 KB Output is correct
36 Correct 19 ms 520 KB Output is correct
37 Correct 38 ms 520 KB Output is correct
38 Correct 45 ms 520 KB Output is correct
39 Correct 22 ms 508 KB Output is correct
40 Correct 12 ms 616 KB Output is correct
41 Correct 12 ms 468 KB Output is correct
42 Correct 13 ms 512 KB Output is correct
43 Correct 15 ms 468 KB Output is correct
44 Correct 15 ms 516 KB Output is correct
45 Correct 16 ms 460 KB Output is correct
46 Correct 21 ms 524 KB Output is correct
47 Correct 16 ms 512 KB Output is correct
48 Correct 16 ms 468 KB Output is correct
49 Correct 18 ms 516 KB Output is correct
50 Correct 23 ms 524 KB Output is correct
51 Correct 16 ms 504 KB Output is correct
52 Correct 16 ms 512 KB Output is correct
53 Correct 16 ms 456 KB Output is correct
54 Correct 21 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 170 ms 7552 KB Output is correct
4 Correct 159 ms 9548 KB Output is correct
5 Correct 176 ms 8032 KB Output is correct
6 Correct 167 ms 7612 KB Output is correct
7 Correct 169 ms 7524 KB Output is correct
8 Correct 148 ms 7276 KB Output is correct
9 Correct 153 ms 7664 KB Output is correct
10 Correct 153 ms 8868 KB Output is correct
11 Correct 171 ms 7628 KB Output is correct
12 Correct 173 ms 8512 KB Output is correct
13 Correct 169 ms 6652 KB Output is correct
14 Correct 168 ms 7148 KB Output is correct
15 Correct 168 ms 8096 KB Output is correct
16 Correct 178 ms 8776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 170 ms 7552 KB Output is correct
30 Correct 159 ms 9548 KB Output is correct
31 Correct 176 ms 8032 KB Output is correct
32 Correct 167 ms 7612 KB Output is correct
33 Correct 169 ms 7524 KB Output is correct
34 Correct 148 ms 7276 KB Output is correct
35 Correct 153 ms 7664 KB Output is correct
36 Correct 153 ms 8868 KB Output is correct
37 Correct 171 ms 7628 KB Output is correct
38 Correct 173 ms 8512 KB Output is correct
39 Correct 169 ms 6652 KB Output is correct
40 Correct 168 ms 7148 KB Output is correct
41 Correct 168 ms 8096 KB Output is correct
42 Correct 178 ms 8776 KB Output is correct
43 Correct 618 ms 11848 KB Output is correct
44 Correct 1381 ms 13684 KB Output is correct
45 Correct 1284 ms 13936 KB Output is correct
46 Correct 230 ms 11712 KB Output is correct
47 Correct 249 ms 11744 KB Output is correct
48 Correct 544 ms 11332 KB Output is correct
49 Correct 844 ms 12996 KB Output is correct
50 Correct 887 ms 11604 KB Output is correct
51 Correct 787 ms 12544 KB Output is correct
52 Correct 749 ms 13196 KB Output is correct
53 Correct 648 ms 10748 KB Output is correct
54 Correct 521 ms 11396 KB Output is correct
55 Correct 721 ms 12256 KB Output is correct
56 Correct 860 ms 13168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 14 ms 480 KB Output is correct
30 Correct 19 ms 508 KB Output is correct
31 Correct 17 ms 512 KB Output is correct
32 Correct 12 ms 468 KB Output is correct
33 Correct 7 ms 500 KB Output is correct
34 Correct 19 ms 468 KB Output is correct
35 Correct 21 ms 528 KB Output is correct
36 Correct 19 ms 520 KB Output is correct
37 Correct 38 ms 520 KB Output is correct
38 Correct 45 ms 520 KB Output is correct
39 Correct 22 ms 508 KB Output is correct
40 Correct 12 ms 616 KB Output is correct
41 Correct 12 ms 468 KB Output is correct
42 Correct 13 ms 512 KB Output is correct
43 Correct 15 ms 468 KB Output is correct
44 Correct 15 ms 516 KB Output is correct
45 Correct 16 ms 460 KB Output is correct
46 Correct 21 ms 524 KB Output is correct
47 Correct 16 ms 512 KB Output is correct
48 Correct 16 ms 468 KB Output is correct
49 Correct 18 ms 516 KB Output is correct
50 Correct 23 ms 524 KB Output is correct
51 Correct 16 ms 504 KB Output is correct
52 Correct 16 ms 512 KB Output is correct
53 Correct 16 ms 456 KB Output is correct
54 Correct 21 ms 524 KB Output is correct
55 Execution timed out 2071 ms 8252 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 14 ms 480 KB Output is correct
30 Correct 19 ms 508 KB Output is correct
31 Correct 17 ms 512 KB Output is correct
32 Correct 12 ms 468 KB Output is correct
33 Correct 7 ms 500 KB Output is correct
34 Correct 19 ms 468 KB Output is correct
35 Correct 21 ms 528 KB Output is correct
36 Correct 19 ms 520 KB Output is correct
37 Correct 38 ms 520 KB Output is correct
38 Correct 45 ms 520 KB Output is correct
39 Correct 22 ms 508 KB Output is correct
40 Correct 12 ms 616 KB Output is correct
41 Correct 12 ms 468 KB Output is correct
42 Correct 13 ms 512 KB Output is correct
43 Correct 15 ms 468 KB Output is correct
44 Correct 15 ms 516 KB Output is correct
45 Correct 16 ms 460 KB Output is correct
46 Correct 21 ms 524 KB Output is correct
47 Correct 16 ms 512 KB Output is correct
48 Correct 16 ms 468 KB Output is correct
49 Correct 18 ms 516 KB Output is correct
50 Correct 23 ms 524 KB Output is correct
51 Correct 16 ms 504 KB Output is correct
52 Correct 16 ms 512 KB Output is correct
53 Correct 16 ms 456 KB Output is correct
54 Correct 21 ms 524 KB Output is correct
55 Correct 170 ms 7552 KB Output is correct
56 Correct 159 ms 9548 KB Output is correct
57 Correct 176 ms 8032 KB Output is correct
58 Correct 167 ms 7612 KB Output is correct
59 Correct 169 ms 7524 KB Output is correct
60 Correct 148 ms 7276 KB Output is correct
61 Correct 153 ms 7664 KB Output is correct
62 Correct 153 ms 8868 KB Output is correct
63 Correct 171 ms 7628 KB Output is correct
64 Correct 173 ms 8512 KB Output is correct
65 Correct 169 ms 6652 KB Output is correct
66 Correct 168 ms 7148 KB Output is correct
67 Correct 168 ms 8096 KB Output is correct
68 Correct 178 ms 8776 KB Output is correct
69 Correct 618 ms 11848 KB Output is correct
70 Correct 1381 ms 13684 KB Output is correct
71 Correct 1284 ms 13936 KB Output is correct
72 Correct 230 ms 11712 KB Output is correct
73 Correct 249 ms 11744 KB Output is correct
74 Correct 544 ms 11332 KB Output is correct
75 Correct 844 ms 12996 KB Output is correct
76 Correct 887 ms 11604 KB Output is correct
77 Correct 787 ms 12544 KB Output is correct
78 Correct 749 ms 13196 KB Output is correct
79 Correct 648 ms 10748 KB Output is correct
80 Correct 521 ms 11396 KB Output is correct
81 Correct 721 ms 12256 KB Output is correct
82 Correct 860 ms 13168 KB Output is correct
83 Execution timed out 2071 ms 8252 KB Time limit exceeded
84 Halted 0 ms 0 KB -