Submission #990323

# Submission time Handle Problem Language Result Execution time Memory
990323 2024-05-30T08:02:37 Z imarn Joker (BOI20_joker) C++14
100 / 100
250 ms 21444 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int mxn=4e5+5;
vector<pii>edge;
int pr[mxn]{0},m,n;
int dp[mxn]{0};
int sz[mxn]{0};
stack<pii>st;
bool ok=0;
void rollback(int x){
    while(st.size()>x){
        if(st.top().f==-1){
            st.pop();ok=0;continue;
        }
        pr[st.top().f]=st.top().f;
        sz[st.top().s]-=sz[st.top().f];
        st.pop();
    }
}
int get(int r){
    return pr[r]==r?r:get(pr[r]);
}
void uni2(int a,int b){
    a=get(a),b=get(b);
    if(a==b)return;
    if(sz[a]>sz[b])swap(a,b);
    pr[a]=b;sz[b]+=sz[a];
    st.push({a,b});
}
void uni(int a,int b){
    uni2(a,b+n);uni2(a+n,b);
    if(!ok&&(get(a)==get(a+n)||get(b)==get(b+n)))ok=1,st.push({-1,-1});
}
void solve(int l1,int r1,int l2,int r2){
    if(l1>r1)return;
    int md=(l1+r1)>>1,md2=-1;
    int pv1=st.size();
    for(int i=l1;i<=md-1;i++){
        uni(edge[i-1].f,edge[i-1].s);
    }int pv2=st.size();
    for(int i=r2;i>=max(l2,md);i--){
        if(ok){md2=i;break;}
        uni(edge[i-1].f,edge[i-1].s);
    }if(md2==-1)md2=md-1;
    dp[md]=md2;rollback(pv2);
    uni(edge[md-1].f,edge[md-1].s);
    solve(md+1,r1,md2,r2);
    rollback(pv1);
    for(int i=r2;i>=md2+1;i--){
        uni(edge[i-1].f,edge[i-1].s);
    }
    solve(l1,md-1,l2,md2);rollback(pv1);
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int q;cin>>n>>m>>q;iota(pr,pr+2*n+1,0);
    for(int i=1;i<=2*n;i++)sz[i]=1;
    for(int i=0;i<m;i++){
        int u,v;cin>>u>>v;
        edge.pb({u,v});
    }solve(1,m,1,m);
    while(q--){
        int l,r;cin>>l>>r;
        cout<<(r<=dp[l]?"YES\n":"NO\n");
    }
}

Compilation message

Joker.cpp: In function 'void rollback(int)':
Joker.cpp:17:20: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |     while(st.size()>x){
      |           ~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4560 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4560 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4560 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4560 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4524 KB Output is correct
32 Correct 2 ms 4440 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 2 ms 4712 KB Output is correct
35 Correct 2 ms 4680 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
40 Correct 2 ms 4440 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4668 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4700 KB Output is correct
46 Correct 2 ms 4724 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 2 ms 4688 KB Output is correct
49 Correct 2 ms 4700 KB Output is correct
50 Correct 2 ms 4700 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4700 KB Output is correct
54 Correct 2 ms 4672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 145 ms 11672 KB Output is correct
4 Correct 243 ms 15876 KB Output is correct
5 Correct 126 ms 14524 KB Output is correct
6 Correct 138 ms 11668 KB Output is correct
7 Correct 142 ms 11968 KB Output is correct
8 Correct 147 ms 10460 KB Output is correct
9 Correct 180 ms 11712 KB Output is correct
10 Correct 235 ms 14552 KB Output is correct
11 Correct 157 ms 11628 KB Output is correct
12 Correct 190 ms 14012 KB Output is correct
13 Correct 140 ms 8896 KB Output is correct
14 Correct 148 ms 10356 KB Output is correct
15 Correct 229 ms 13764 KB Output is correct
16 Correct 237 ms 14524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4560 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4560 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 145 ms 11672 KB Output is correct
30 Correct 243 ms 15876 KB Output is correct
31 Correct 126 ms 14524 KB Output is correct
32 Correct 138 ms 11668 KB Output is correct
33 Correct 142 ms 11968 KB Output is correct
34 Correct 147 ms 10460 KB Output is correct
35 Correct 180 ms 11712 KB Output is correct
36 Correct 235 ms 14552 KB Output is correct
37 Correct 157 ms 11628 KB Output is correct
38 Correct 190 ms 14012 KB Output is correct
39 Correct 140 ms 8896 KB Output is correct
40 Correct 148 ms 10356 KB Output is correct
41 Correct 229 ms 13764 KB Output is correct
42 Correct 237 ms 14524 KB Output is correct
43 Correct 151 ms 16316 KB Output is correct
44 Correct 247 ms 20008 KB Output is correct
45 Correct 205 ms 19780 KB Output is correct
46 Correct 141 ms 16060 KB Output is correct
47 Correct 139 ms 16064 KB Output is correct
48 Correct 196 ms 16320 KB Output is correct
49 Correct 250 ms 18364 KB Output is correct
50 Correct 150 ms 15656 KB Output is correct
51 Correct 178 ms 17084 KB Output is correct
52 Correct 207 ms 18620 KB Output is correct
53 Correct 147 ms 13248 KB Output is correct
54 Correct 182 ms 16068 KB Output is correct
55 Correct 224 ms 17188 KB Output is correct
56 Correct 241 ms 18616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4560 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4560 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4524 KB Output is correct
32 Correct 2 ms 4440 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 2 ms 4712 KB Output is correct
35 Correct 2 ms 4680 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
40 Correct 2 ms 4440 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4668 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4700 KB Output is correct
46 Correct 2 ms 4724 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 2 ms 4688 KB Output is correct
49 Correct 2 ms 4700 KB Output is correct
50 Correct 2 ms 4700 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4700 KB Output is correct
54 Correct 2 ms 4672 KB Output is correct
55 Correct 129 ms 13252 KB Output is correct
56 Correct 227 ms 17328 KB Output is correct
57 Correct 96 ms 16324 KB Output is correct
58 Correct 119 ms 13248 KB Output is correct
59 Correct 168 ms 13988 KB Output is correct
60 Correct 221 ms 15236 KB Output is correct
61 Correct 160 ms 14288 KB Output is correct
62 Correct 175 ms 15812 KB Output is correct
63 Correct 122 ms 11476 KB Output is correct
64 Correct 186 ms 14032 KB Output is correct
65 Correct 224 ms 15940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4560 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4560 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4524 KB Output is correct
32 Correct 2 ms 4440 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 2 ms 4712 KB Output is correct
35 Correct 2 ms 4680 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
40 Correct 2 ms 4440 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4668 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4700 KB Output is correct
46 Correct 2 ms 4724 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 2 ms 4688 KB Output is correct
49 Correct 2 ms 4700 KB Output is correct
50 Correct 2 ms 4700 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4700 KB Output is correct
54 Correct 2 ms 4672 KB Output is correct
55 Correct 145 ms 11672 KB Output is correct
56 Correct 243 ms 15876 KB Output is correct
57 Correct 126 ms 14524 KB Output is correct
58 Correct 138 ms 11668 KB Output is correct
59 Correct 142 ms 11968 KB Output is correct
60 Correct 147 ms 10460 KB Output is correct
61 Correct 180 ms 11712 KB Output is correct
62 Correct 235 ms 14552 KB Output is correct
63 Correct 157 ms 11628 KB Output is correct
64 Correct 190 ms 14012 KB Output is correct
65 Correct 140 ms 8896 KB Output is correct
66 Correct 148 ms 10356 KB Output is correct
67 Correct 229 ms 13764 KB Output is correct
68 Correct 237 ms 14524 KB Output is correct
69 Correct 151 ms 16316 KB Output is correct
70 Correct 247 ms 20008 KB Output is correct
71 Correct 205 ms 19780 KB Output is correct
72 Correct 141 ms 16060 KB Output is correct
73 Correct 139 ms 16064 KB Output is correct
74 Correct 196 ms 16320 KB Output is correct
75 Correct 250 ms 18364 KB Output is correct
76 Correct 150 ms 15656 KB Output is correct
77 Correct 178 ms 17084 KB Output is correct
78 Correct 207 ms 18620 KB Output is correct
79 Correct 147 ms 13248 KB Output is correct
80 Correct 182 ms 16068 KB Output is correct
81 Correct 224 ms 17188 KB Output is correct
82 Correct 241 ms 18616 KB Output is correct
83 Correct 129 ms 13252 KB Output is correct
84 Correct 227 ms 17328 KB Output is correct
85 Correct 96 ms 16324 KB Output is correct
86 Correct 119 ms 13248 KB Output is correct
87 Correct 168 ms 13988 KB Output is correct
88 Correct 221 ms 15236 KB Output is correct
89 Correct 160 ms 14288 KB Output is correct
90 Correct 175 ms 15812 KB Output is correct
91 Correct 122 ms 11476 KB Output is correct
92 Correct 186 ms 14032 KB Output is correct
93 Correct 224 ms 15940 KB Output is correct
94 Correct 151 ms 17600 KB Output is correct
95 Correct 188 ms 20412 KB Output is correct
96 Correct 127 ms 20408 KB Output is correct
97 Correct 140 ms 16572 KB Output is correct
98 Correct 149 ms 17352 KB Output is correct
99 Correct 168 ms 15292 KB Output is correct
100 Correct 220 ms 19412 KB Output is correct
101 Correct 172 ms 16060 KB Output is correct
102 Correct 203 ms 18108 KB Output is correct
103 Correct 213 ms 20224 KB Output is correct
104 Correct 152 ms 14780 KB Output is correct
105 Correct 225 ms 17848 KB Output is correct
106 Correct 241 ms 19752 KB Output is correct
107 Correct 125 ms 21444 KB Output is correct
108 Correct 153 ms 16576 KB Output is correct
109 Correct 150 ms 17084 KB Output is correct
110 Correct 150 ms 17400 KB Output is correct
111 Correct 153 ms 16572 KB Output is correct
112 Correct 151 ms 16572 KB Output is correct
113 Correct 150 ms 16528 KB Output is correct
114 Correct 152 ms 16576 KB Output is correct
115 Correct 149 ms 16568 KB Output is correct
116 Correct 153 ms 16572 KB Output is correct