# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
257653 | 2020-08-04T14:02:34 Z | arnold518 | Joker (BOI20_joker) | C++14 | 2000 ms | 27644 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 4e5; const int SQ = 1000; struct Query { int l, r, k; bool operator < (const Query &p) { return r>p.r; } }; int N, M, Q; pii E[MAXN+10]; Query A[MAXN+10]; vector<Query> B[MAXN+10]; int ans[MAXN+10]; struct UF { //int par[MAXN+10], sz[MAXN+10], opp[MAXN+10]; vector<int> par, sz, opp; bool state; vector<int> V; void init() { par.resize(2*N+10); sz.resize(2*N+10); opp.resize(2*N+10); int i, j; for(i=1; i<=N; i++) par[i]=i, sz[i]=1, opp[i]=N+i; for(i=1; i<=N; i++) par[i+N]=i+N, sz[i+N]=1, opp[i+N]=i; V.clear(); state=true; } int Find(int x) { if(x==par[x]) return x; return Find(par[x]); } void Union(int x, int y) { //printf("Union %d %d\n", x, y); x=Find(x); y=Find(y); int nx=opp[x], ny=opp[y]; if(x==y || !state) { if(state) V.push_back(-1); else V.push_back(-2); state=false; return; } if(sz[x]<sz[ny]) swap(x, ny); if(sz[y]<sz[nx]) swap(y, nx); V.push_back(opp[x]); V.push_back(opp[y]); V.push_back(ny); V.push_back(nx); par[ny]=x; sz[x]+=sz[ny]; par[nx]=y; sz[y]+=sz[nx]; opp[x]=y; opp[y]=x; } void restore() { int ny, nx, x, y, oppx, oppy; //printf("RESTORE\n"); if(V.empty()) while(1); if(V.back()<0) { if(V.back()==-1) state=true; V.pop_back(); return; } nx=V.back(); V.pop_back(); ny=V.back(); V.pop_back(); oppy=V.back(); V.pop_back(); oppx=V.back(); V.pop_back(); x=par[ny]; y=par[nx]; opp[x]=oppx; opp[y]=oppy; sz[x]-=sz[ny]; sz[y]-=sz[nx]; par[ny]=ny; par[nx]=nx; } }uf; int main() { int i, j, k; scanf("%d%d%d", &N, &M, &Q); for(i=1; i<=M; i++) scanf("%d%d", &E[i].first, &E[i].second); for(i=1; i<=Q; i++) { scanf("%d%d", &A[i].l, &A[i].r); A[i].k=i; B[A[i].l/SQ].push_back(A[i]); } uf.init(); for(i=0, j=1; i<=M/SQ; i++) { int l=max(SQ*i, 1), r=min(SQ*i+SQ-1, M); sort(B[i].begin(), B[i].end()); for(; j<l; j++) uf.Union(E[j].first, E[j].second); int p=M, q; for(auto it : B[i]) { for(; p>it.r; p--) uf.Union(E[p].first, E[p].second); for(q=l; q<it.l; q++) uf.Union(E[q].first, E[q].second); ans[it.k]=uf.state; for(q=l; q<it.l; q++) uf.restore(); } for(p++; p<=M; p++) uf.restore(); } for(i=1; i<=Q; i++) { if(!ans[i]) printf("YES\n"); else printf("NO\n"); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 9728 KB | Output is correct |
2 | Correct | 6 ms | 9728 KB | Output is correct |
3 | Correct | 6 ms | 9728 KB | Output is correct |
4 | Correct | 9 ms | 9728 KB | Output is correct |
5 | Correct | 8 ms | 9728 KB | Output is correct |
6 | Correct | 8 ms | 9728 KB | Output is correct |
7 | Correct | 8 ms | 9728 KB | Output is correct |
8 | Correct | 7 ms | 9728 KB | Output is correct |
9 | Correct | 9 ms | 9728 KB | Output is correct |
10 | Correct | 9 ms | 9728 KB | Output is correct |
11 | Correct | 8 ms | 9808 KB | Output is correct |
12 | Correct | 10 ms | 9728 KB | Output is correct |
13 | Correct | 7 ms | 9728 KB | Output is correct |
14 | Correct | 10 ms | 9728 KB | Output is correct |
15 | Correct | 11 ms | 9728 KB | Output is correct |
16 | Correct | 11 ms | 9728 KB | Output is correct |
17 | Correct | 8 ms | 9728 KB | Output is correct |
18 | Correct | 11 ms | 9728 KB | Output is correct |
19 | Correct | 11 ms | 9728 KB | Output is correct |
20 | Correct | 11 ms | 9728 KB | Output is correct |
21 | Correct | 10 ms | 9728 KB | Output is correct |
22 | Correct | 9 ms | 9728 KB | Output is correct |
23 | Correct | 9 ms | 9728 KB | Output is correct |
24 | Correct | 10 ms | 9728 KB | Output is correct |
25 | Correct | 10 ms | 9728 KB | Output is correct |
26 | Correct | 8 ms | 9728 KB | Output is correct |
27 | Correct | 8 ms | 9728 KB | Output is correct |
28 | Correct | 7 ms | 9728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 9728 KB | Output is correct |
2 | Correct | 6 ms | 9728 KB | Output is correct |
3 | Correct | 6 ms | 9728 KB | Output is correct |
4 | Correct | 9 ms | 9728 KB | Output is correct |
5 | Correct | 8 ms | 9728 KB | Output is correct |
6 | Correct | 8 ms | 9728 KB | Output is correct |
7 | Correct | 8 ms | 9728 KB | Output is correct |
8 | Correct | 7 ms | 9728 KB | Output is correct |
9 | Correct | 9 ms | 9728 KB | Output is correct |
10 | Correct | 9 ms | 9728 KB | Output is correct |
11 | Correct | 8 ms | 9808 KB | Output is correct |
12 | Correct | 10 ms | 9728 KB | Output is correct |
13 | Correct | 7 ms | 9728 KB | Output is correct |
14 | Correct | 10 ms | 9728 KB | Output is correct |
15 | Correct | 11 ms | 9728 KB | Output is correct |
16 | Correct | 11 ms | 9728 KB | Output is correct |
17 | Correct | 8 ms | 9728 KB | Output is correct |
18 | Correct | 11 ms | 9728 KB | Output is correct |
19 | Correct | 11 ms | 9728 KB | Output is correct |
20 | Correct | 11 ms | 9728 KB | Output is correct |
21 | Correct | 10 ms | 9728 KB | Output is correct |
22 | Correct | 9 ms | 9728 KB | Output is correct |
23 | Correct | 9 ms | 9728 KB | Output is correct |
24 | Correct | 10 ms | 9728 KB | Output is correct |
25 | Correct | 10 ms | 9728 KB | Output is correct |
26 | Correct | 8 ms | 9728 KB | Output is correct |
27 | Correct | 8 ms | 9728 KB | Output is correct |
28 | Correct | 7 ms | 9728 KB | Output is correct |
29 | Correct | 42 ms | 9856 KB | Output is correct |
30 | Correct | 34 ms | 9856 KB | Output is correct |
31 | Correct | 38 ms | 9856 KB | Output is correct |
32 | Correct | 40 ms | 9856 KB | Output is correct |
33 | Correct | 39 ms | 9856 KB | Output is correct |
34 | Correct | 44 ms | 9856 KB | Output is correct |
35 | Correct | 44 ms | 9960 KB | Output is correct |
36 | Correct | 29 ms | 9940 KB | Output is correct |
37 | Correct | 40 ms | 9960 KB | Output is correct |
38 | Correct | 50 ms | 9976 KB | Output is correct |
39 | Correct | 68 ms | 9932 KB | Output is correct |
40 | Correct | 154 ms | 9856 KB | Output is correct |
41 | Correct | 129 ms | 9856 KB | Output is correct |
42 | Correct | 121 ms | 9856 KB | Output is correct |
43 | Correct | 296 ms | 9856 KB | Output is correct |
44 | Correct | 316 ms | 9928 KB | Output is correct |
45 | Correct | 36 ms | 9936 KB | Output is correct |
46 | Correct | 50 ms | 9856 KB | Output is correct |
47 | Correct | 317 ms | 9924 KB | Output is correct |
48 | Correct | 89 ms | 9856 KB | Output is correct |
49 | Correct | 47 ms | 9856 KB | Output is correct |
50 | Correct | 46 ms | 9960 KB | Output is correct |
51 | Correct | 228 ms | 9856 KB | Output is correct |
52 | Correct | 204 ms | 10036 KB | Output is correct |
53 | Correct | 129 ms | 9856 KB | Output is correct |
54 | Correct | 43 ms | 9856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 9728 KB | Output is correct |
2 | Correct | 6 ms | 9728 KB | Output is correct |
3 | Correct | 154 ms | 23780 KB | Output is correct |
4 | Correct | 175 ms | 27644 KB | Output is correct |
5 | Correct | 162 ms | 27216 KB | Output is correct |
6 | Correct | 154 ms | 23776 KB | Output is correct |
7 | Correct | 165 ms | 23776 KB | Output is correct |
8 | Execution timed out | 2080 ms | 21508 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 9728 KB | Output is correct |
2 | Correct | 6 ms | 9728 KB | Output is correct |
3 | Correct | 6 ms | 9728 KB | Output is correct |
4 | Correct | 9 ms | 9728 KB | Output is correct |
5 | Correct | 8 ms | 9728 KB | Output is correct |
6 | Correct | 8 ms | 9728 KB | Output is correct |
7 | Correct | 8 ms | 9728 KB | Output is correct |
8 | Correct | 7 ms | 9728 KB | Output is correct |
9 | Correct | 9 ms | 9728 KB | Output is correct |
10 | Correct | 9 ms | 9728 KB | Output is correct |
11 | Correct | 8 ms | 9808 KB | Output is correct |
12 | Correct | 10 ms | 9728 KB | Output is correct |
13 | Correct | 7 ms | 9728 KB | Output is correct |
14 | Correct | 10 ms | 9728 KB | Output is correct |
15 | Correct | 11 ms | 9728 KB | Output is correct |
16 | Correct | 11 ms | 9728 KB | Output is correct |
17 | Correct | 8 ms | 9728 KB | Output is correct |
18 | Correct | 11 ms | 9728 KB | Output is correct |
19 | Correct | 11 ms | 9728 KB | Output is correct |
20 | Correct | 11 ms | 9728 KB | Output is correct |
21 | Correct | 10 ms | 9728 KB | Output is correct |
22 | Correct | 9 ms | 9728 KB | Output is correct |
23 | Correct | 9 ms | 9728 KB | Output is correct |
24 | Correct | 10 ms | 9728 KB | Output is correct |
25 | Correct | 10 ms | 9728 KB | Output is correct |
26 | Correct | 8 ms | 9728 KB | Output is correct |
27 | Correct | 8 ms | 9728 KB | Output is correct |
28 | Correct | 7 ms | 9728 KB | Output is correct |
29 | Correct | 154 ms | 23780 KB | Output is correct |
30 | Correct | 175 ms | 27644 KB | Output is correct |
31 | Correct | 162 ms | 27216 KB | Output is correct |
32 | Correct | 154 ms | 23776 KB | Output is correct |
33 | Correct | 165 ms | 23776 KB | Output is correct |
34 | Execution timed out | 2080 ms | 21508 KB | Time limit exceeded |
35 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 9728 KB | Output is correct |
2 | Correct | 6 ms | 9728 KB | Output is correct |
3 | Correct | 6 ms | 9728 KB | Output is correct |
4 | Correct | 9 ms | 9728 KB | Output is correct |
5 | Correct | 8 ms | 9728 KB | Output is correct |
6 | Correct | 8 ms | 9728 KB | Output is correct |
7 | Correct | 8 ms | 9728 KB | Output is correct |
8 | Correct | 7 ms | 9728 KB | Output is correct |
9 | Correct | 9 ms | 9728 KB | Output is correct |
10 | Correct | 9 ms | 9728 KB | Output is correct |
11 | Correct | 8 ms | 9808 KB | Output is correct |
12 | Correct | 10 ms | 9728 KB | Output is correct |
13 | Correct | 7 ms | 9728 KB | Output is correct |
14 | Correct | 10 ms | 9728 KB | Output is correct |
15 | Correct | 11 ms | 9728 KB | Output is correct |
16 | Correct | 11 ms | 9728 KB | Output is correct |
17 | Correct | 8 ms | 9728 KB | Output is correct |
18 | Correct | 11 ms | 9728 KB | Output is correct |
19 | Correct | 11 ms | 9728 KB | Output is correct |
20 | Correct | 11 ms | 9728 KB | Output is correct |
21 | Correct | 10 ms | 9728 KB | Output is correct |
22 | Correct | 9 ms | 9728 KB | Output is correct |
23 | Correct | 9 ms | 9728 KB | Output is correct |
24 | Correct | 10 ms | 9728 KB | Output is correct |
25 | Correct | 10 ms | 9728 KB | Output is correct |
26 | Correct | 8 ms | 9728 KB | Output is correct |
27 | Correct | 8 ms | 9728 KB | Output is correct |
28 | Correct | 7 ms | 9728 KB | Output is correct |
29 | Correct | 42 ms | 9856 KB | Output is correct |
30 | Correct | 34 ms | 9856 KB | Output is correct |
31 | Correct | 38 ms | 9856 KB | Output is correct |
32 | Correct | 40 ms | 9856 KB | Output is correct |
33 | Correct | 39 ms | 9856 KB | Output is correct |
34 | Correct | 44 ms | 9856 KB | Output is correct |
35 | Correct | 44 ms | 9960 KB | Output is correct |
36 | Correct | 29 ms | 9940 KB | Output is correct |
37 | Correct | 40 ms | 9960 KB | Output is correct |
38 | Correct | 50 ms | 9976 KB | Output is correct |
39 | Correct | 68 ms | 9932 KB | Output is correct |
40 | Correct | 154 ms | 9856 KB | Output is correct |
41 | Correct | 129 ms | 9856 KB | Output is correct |
42 | Correct | 121 ms | 9856 KB | Output is correct |
43 | Correct | 296 ms | 9856 KB | Output is correct |
44 | Correct | 316 ms | 9928 KB | Output is correct |
45 | Correct | 36 ms | 9936 KB | Output is correct |
46 | Correct | 50 ms | 9856 KB | Output is correct |
47 | Correct | 317 ms | 9924 KB | Output is correct |
48 | Correct | 89 ms | 9856 KB | Output is correct |
49 | Correct | 47 ms | 9856 KB | Output is correct |
50 | Correct | 46 ms | 9960 KB | Output is correct |
51 | Correct | 228 ms | 9856 KB | Output is correct |
52 | Correct | 204 ms | 10036 KB | Output is correct |
53 | Correct | 129 ms | 9856 KB | Output is correct |
54 | Correct | 43 ms | 9856 KB | Output is correct |
55 | Correct | 606 ms | 15852 KB | Output is correct |
56 | Execution timed out | 2082 ms | 21096 KB | Time limit exceeded |
57 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 9728 KB | Output is correct |
2 | Correct | 6 ms | 9728 KB | Output is correct |
3 | Correct | 6 ms | 9728 KB | Output is correct |
4 | Correct | 9 ms | 9728 KB | Output is correct |
5 | Correct | 8 ms | 9728 KB | Output is correct |
6 | Correct | 8 ms | 9728 KB | Output is correct |
7 | Correct | 8 ms | 9728 KB | Output is correct |
8 | Correct | 7 ms | 9728 KB | Output is correct |
9 | Correct | 9 ms | 9728 KB | Output is correct |
10 | Correct | 9 ms | 9728 KB | Output is correct |
11 | Correct | 8 ms | 9808 KB | Output is correct |
12 | Correct | 10 ms | 9728 KB | Output is correct |
13 | Correct | 7 ms | 9728 KB | Output is correct |
14 | Correct | 10 ms | 9728 KB | Output is correct |
15 | Correct | 11 ms | 9728 KB | Output is correct |
16 | Correct | 11 ms | 9728 KB | Output is correct |
17 | Correct | 8 ms | 9728 KB | Output is correct |
18 | Correct | 11 ms | 9728 KB | Output is correct |
19 | Correct | 11 ms | 9728 KB | Output is correct |
20 | Correct | 11 ms | 9728 KB | Output is correct |
21 | Correct | 10 ms | 9728 KB | Output is correct |
22 | Correct | 9 ms | 9728 KB | Output is correct |
23 | Correct | 9 ms | 9728 KB | Output is correct |
24 | Correct | 10 ms | 9728 KB | Output is correct |
25 | Correct | 10 ms | 9728 KB | Output is correct |
26 | Correct | 8 ms | 9728 KB | Output is correct |
27 | Correct | 8 ms | 9728 KB | Output is correct |
28 | Correct | 7 ms | 9728 KB | Output is correct |
29 | Correct | 42 ms | 9856 KB | Output is correct |
30 | Correct | 34 ms | 9856 KB | Output is correct |
31 | Correct | 38 ms | 9856 KB | Output is correct |
32 | Correct | 40 ms | 9856 KB | Output is correct |
33 | Correct | 39 ms | 9856 KB | Output is correct |
34 | Correct | 44 ms | 9856 KB | Output is correct |
35 | Correct | 44 ms | 9960 KB | Output is correct |
36 | Correct | 29 ms | 9940 KB | Output is correct |
37 | Correct | 40 ms | 9960 KB | Output is correct |
38 | Correct | 50 ms | 9976 KB | Output is correct |
39 | Correct | 68 ms | 9932 KB | Output is correct |
40 | Correct | 154 ms | 9856 KB | Output is correct |
41 | Correct | 129 ms | 9856 KB | Output is correct |
42 | Correct | 121 ms | 9856 KB | Output is correct |
43 | Correct | 296 ms | 9856 KB | Output is correct |
44 | Correct | 316 ms | 9928 KB | Output is correct |
45 | Correct | 36 ms | 9936 KB | Output is correct |
46 | Correct | 50 ms | 9856 KB | Output is correct |
47 | Correct | 317 ms | 9924 KB | Output is correct |
48 | Correct | 89 ms | 9856 KB | Output is correct |
49 | Correct | 47 ms | 9856 KB | Output is correct |
50 | Correct | 46 ms | 9960 KB | Output is correct |
51 | Correct | 228 ms | 9856 KB | Output is correct |
52 | Correct | 204 ms | 10036 KB | Output is correct |
53 | Correct | 129 ms | 9856 KB | Output is correct |
54 | Correct | 43 ms | 9856 KB | Output is correct |
55 | Correct | 154 ms | 23780 KB | Output is correct |
56 | Correct | 175 ms | 27644 KB | Output is correct |
57 | Correct | 162 ms | 27216 KB | Output is correct |
58 | Correct | 154 ms | 23776 KB | Output is correct |
59 | Correct | 165 ms | 23776 KB | Output is correct |
60 | Execution timed out | 2080 ms | 21508 KB | Time limit exceeded |
61 | Halted | 0 ms | 0 KB | - |