Submission #256142

# Submission time Handle Problem Language Result Execution time Memory
256142 2020-08-02T10:17:22 Z 문홍윤(#5033) Joker (BOI20_joker) C++17
100 / 100
513 ms 8200 KB
#include <bits/stdc++.h>
#define pb emplace_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int inf=987654321;

struct UNION_FIND{
    int par[400010], sz[400010];
    vector<int> vc;
    UNION_FIND(){for(int i=1; i<=400000; i++)par[i]=i, sz[i]=1;}
    int findpar(int num){return num==par[num]?num:findpar(par[num]);}
    void mergepar(int a, int b){
        a=findpar(a);
        b=findpar(b);
        if(a==b)return;
        if(sz[a]<sz[b])swap(a, b);
        vc.pb(b);
        par[b]=a;
        sz[a]+=sz[b];
    }
    void rollback(){
        int tmp=vc.back();
        vc.pop_back();
        sz[par[tmp]]-=sz[tmp];
        par[tmp]=tmp;
    }
}uf;

int n, m, q, ans[200010], l, r;
pii edg[200010];

int link(int a, int b){
    uf.mergepar(2*a-1, 2*b);
    uf.mergepar(2*a, 2*b-1);
    if(uf.findpar(2*a)==uf.findpar(2*a-1))return 1;
    return 0;
}

void dnc(int sa, int ea, int sb, int eb){
    if(sa>ea)return;
    int mid=(sa+ea)/2;
    int tmp1=uf.vc.size();
    for(int i=l+1; i<=mid; i++)link(edg[i].F, edg[i].S);
    l=mid;
    int tmp2=uf.vc.size();
    for(int i=r-1; i>l&&i>=sb; i--){
        int sz=uf.vc.size();
        int tmp=link(edg[i].F, edg[i].S);
        if(tmp){
            while(sz<uf.vc.size())uf.rollback();
            break;
        }
        r=i;
    }
    ans[mid]=r;
    while(tmp2<uf.vc.size())uf.rollback();
    r=eb;
    link(edg[mid+1].F, edg[mid+1].S);
    l=mid+1;
    dnc(mid+1, ea, ans[mid], eb);
    while(tmp1<uf.vc.size())uf.rollback();
    l=sa;
    for(int i=r-1; i>=ans[mid]; i--)link(edg[i].F, edg[i].S);
    r=ans[mid];
    dnc(sa, mid-1, sb, ans[mid]);
    while(tmp1<uf.vc.size())uf.rollback();
    r=eb;
}

int main(){
    scanf("%d %d %d", &n, &m, &q);
    int np=0;
    for(int i=1; i<=m; i++)scanf("%d %d", &edg[i].F, &edg[i].S);
    int ll=m, lr=1;
    for(int i=1; i<=m; i++){
        if(link(edg[i].F, edg[i].S)){
            ll=i-1;
            break;
        }
    }
    while(uf.vc.size())uf.rollback();
    for(int i=m; i>=1; i--){
        if(link(edg[i].F, edg[i].S)){
            lr=i+1;
            break;
        }
    }
    while(uf.vc.size())uf.rollback();
    r=m+1;
    dnc(0, ll, lr, m+1);
    for(int i=ll+1; i<=m; i++)ans[i]=inf;
    for(int i=1; i<=q; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        if(ans[a-1]<=b+1)puts("NO");
        else puts("YES");
    }
}

Compilation message

Joker.cpp: In function 'void dnc(int, int, int, int)':
Joker.cpp:54:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(sz<uf.vc.size())uf.rollback();
                   ~~^~~~~~~~~~~~~
Joker.cpp:60:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(tmp2<uf.vc.size())uf.rollback();
           ~~~~^~~~~~~~~~~~~
Joker.cpp:65:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(tmp1<uf.vc.size())uf.rollback();
           ~~~~^~~~~~~~~~~~~
Joker.cpp:70:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(tmp1<uf.vc.size())uf.rollback();
           ~~~~^~~~~~~~~~~~~
Joker.cpp: In function 'int main()':
Joker.cpp:76:9: warning: unused variable 'np' [-Wunused-variable]
     int np=0;
         ^~
Joker.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &m, &q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:77:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=m; i++)scanf("%d %d", &edg[i].F, &edg[i].S);
                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 2 ms 3456 KB Output is correct
8 Correct 2 ms 3456 KB Output is correct
9 Correct 2 ms 3456 KB Output is correct
10 Correct 2 ms 3456 KB Output is correct
11 Correct 3 ms 3456 KB Output is correct
12 Correct 2 ms 3456 KB Output is correct
13 Correct 4 ms 3456 KB Output is correct
14 Correct 2 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 2 ms 3456 KB Output is correct
17 Correct 2 ms 3456 KB Output is correct
18 Correct 2 ms 3456 KB Output is correct
19 Correct 2 ms 3456 KB Output is correct
20 Correct 2 ms 3456 KB Output is correct
21 Correct 2 ms 3456 KB Output is correct
22 Correct 2 ms 3456 KB Output is correct
23 Correct 2 ms 3456 KB Output is correct
24 Correct 2 ms 3456 KB Output is correct
25 Correct 2 ms 3456 KB Output is correct
26 Correct 2 ms 3456 KB Output is correct
27 Correct 2 ms 3456 KB Output is correct
28 Correct 2 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 2 ms 3456 KB Output is correct
8 Correct 2 ms 3456 KB Output is correct
9 Correct 2 ms 3456 KB Output is correct
10 Correct 2 ms 3456 KB Output is correct
11 Correct 3 ms 3456 KB Output is correct
12 Correct 2 ms 3456 KB Output is correct
13 Correct 4 ms 3456 KB Output is correct
14 Correct 2 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 2 ms 3456 KB Output is correct
17 Correct 2 ms 3456 KB Output is correct
18 Correct 2 ms 3456 KB Output is correct
19 Correct 2 ms 3456 KB Output is correct
20 Correct 2 ms 3456 KB Output is correct
21 Correct 2 ms 3456 KB Output is correct
22 Correct 2 ms 3456 KB Output is correct
23 Correct 2 ms 3456 KB Output is correct
24 Correct 2 ms 3456 KB Output is correct
25 Correct 2 ms 3456 KB Output is correct
26 Correct 2 ms 3456 KB Output is correct
27 Correct 2 ms 3456 KB Output is correct
28 Correct 2 ms 3456 KB Output is correct
29 Correct 4 ms 3456 KB Output is correct
30 Correct 4 ms 3456 KB Output is correct
31 Correct 4 ms 3456 KB Output is correct
32 Correct 5 ms 3456 KB Output is correct
33 Correct 4 ms 3456 KB Output is correct
34 Correct 5 ms 3456 KB Output is correct
35 Correct 5 ms 3456 KB Output is correct
36 Correct 4 ms 3456 KB Output is correct
37 Correct 6 ms 3456 KB Output is correct
38 Correct 6 ms 3584 KB Output is correct
39 Correct 4 ms 3456 KB Output is correct
40 Correct 5 ms 3456 KB Output is correct
41 Correct 4 ms 3456 KB Output is correct
42 Correct 4 ms 3456 KB Output is correct
43 Correct 4 ms 3456 KB Output is correct
44 Correct 4 ms 3456 KB Output is correct
45 Correct 4 ms 3456 KB Output is correct
46 Correct 5 ms 3456 KB Output is correct
47 Correct 4 ms 3456 KB Output is correct
48 Correct 5 ms 3456 KB Output is correct
49 Correct 4 ms 3456 KB Output is correct
50 Correct 5 ms 3456 KB Output is correct
51 Correct 4 ms 3456 KB Output is correct
52 Correct 4 ms 3584 KB Output is correct
53 Correct 4 ms 3456 KB Output is correct
54 Correct 4 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 237 ms 7404 KB Output is correct
4 Correct 513 ms 8200 KB Output is correct
5 Correct 273 ms 8036 KB Output is correct
6 Correct 214 ms 7400 KB Output is correct
7 Correct 228 ms 7404 KB Output is correct
8 Correct 226 ms 7280 KB Output is correct
9 Correct 265 ms 7404 KB Output is correct
10 Correct 359 ms 7492 KB Output is correct
11 Correct 268 ms 7404 KB Output is correct
12 Correct 309 ms 7400 KB Output is correct
13 Correct 210 ms 6772 KB Output is correct
14 Correct 218 ms 7024 KB Output is correct
15 Correct 311 ms 7272 KB Output is correct
16 Correct 338 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 2 ms 3456 KB Output is correct
8 Correct 2 ms 3456 KB Output is correct
9 Correct 2 ms 3456 KB Output is correct
10 Correct 2 ms 3456 KB Output is correct
11 Correct 3 ms 3456 KB Output is correct
12 Correct 2 ms 3456 KB Output is correct
13 Correct 4 ms 3456 KB Output is correct
14 Correct 2 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 2 ms 3456 KB Output is correct
17 Correct 2 ms 3456 KB Output is correct
18 Correct 2 ms 3456 KB Output is correct
19 Correct 2 ms 3456 KB Output is correct
20 Correct 2 ms 3456 KB Output is correct
21 Correct 2 ms 3456 KB Output is correct
22 Correct 2 ms 3456 KB Output is correct
23 Correct 2 ms 3456 KB Output is correct
24 Correct 2 ms 3456 KB Output is correct
25 Correct 2 ms 3456 KB Output is correct
26 Correct 2 ms 3456 KB Output is correct
27 Correct 2 ms 3456 KB Output is correct
28 Correct 2 ms 3456 KB Output is correct
29 Correct 237 ms 7404 KB Output is correct
30 Correct 513 ms 8200 KB Output is correct
31 Correct 273 ms 8036 KB Output is correct
32 Correct 214 ms 7400 KB Output is correct
33 Correct 228 ms 7404 KB Output is correct
34 Correct 226 ms 7280 KB Output is correct
35 Correct 265 ms 7404 KB Output is correct
36 Correct 359 ms 7492 KB Output is correct
37 Correct 268 ms 7404 KB Output is correct
38 Correct 309 ms 7400 KB Output is correct
39 Correct 210 ms 6772 KB Output is correct
40 Correct 218 ms 7024 KB Output is correct
41 Correct 311 ms 7272 KB Output is correct
42 Correct 338 ms 7404 KB Output is correct
43 Correct 244 ms 7528 KB Output is correct
44 Correct 429 ms 8036 KB Output is correct
45 Correct 372 ms 8164 KB Output is correct
46 Correct 198 ms 7532 KB Output is correct
47 Correct 205 ms 7428 KB Output is correct
48 Correct 278 ms 7536 KB Output is correct
49 Correct 351 ms 7512 KB Output is correct
50 Correct 251 ms 7272 KB Output is correct
51 Correct 262 ms 7276 KB Output is correct
52 Correct 303 ms 7412 KB Output is correct
53 Correct 220 ms 6772 KB Output is correct
54 Correct 268 ms 7144 KB Output is correct
55 Correct 317 ms 7532 KB Output is correct
56 Correct 360 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 2 ms 3456 KB Output is correct
8 Correct 2 ms 3456 KB Output is correct
9 Correct 2 ms 3456 KB Output is correct
10 Correct 2 ms 3456 KB Output is correct
11 Correct 3 ms 3456 KB Output is correct
12 Correct 2 ms 3456 KB Output is correct
13 Correct 4 ms 3456 KB Output is correct
14 Correct 2 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 2 ms 3456 KB Output is correct
17 Correct 2 ms 3456 KB Output is correct
18 Correct 2 ms 3456 KB Output is correct
19 Correct 2 ms 3456 KB Output is correct
20 Correct 2 ms 3456 KB Output is correct
21 Correct 2 ms 3456 KB Output is correct
22 Correct 2 ms 3456 KB Output is correct
23 Correct 2 ms 3456 KB Output is correct
24 Correct 2 ms 3456 KB Output is correct
25 Correct 2 ms 3456 KB Output is correct
26 Correct 2 ms 3456 KB Output is correct
27 Correct 2 ms 3456 KB Output is correct
28 Correct 2 ms 3456 KB Output is correct
29 Correct 4 ms 3456 KB Output is correct
30 Correct 4 ms 3456 KB Output is correct
31 Correct 4 ms 3456 KB Output is correct
32 Correct 5 ms 3456 KB Output is correct
33 Correct 4 ms 3456 KB Output is correct
34 Correct 5 ms 3456 KB Output is correct
35 Correct 5 ms 3456 KB Output is correct
36 Correct 4 ms 3456 KB Output is correct
37 Correct 6 ms 3456 KB Output is correct
38 Correct 6 ms 3584 KB Output is correct
39 Correct 4 ms 3456 KB Output is correct
40 Correct 5 ms 3456 KB Output is correct
41 Correct 4 ms 3456 KB Output is correct
42 Correct 4 ms 3456 KB Output is correct
43 Correct 4 ms 3456 KB Output is correct
44 Correct 4 ms 3456 KB Output is correct
45 Correct 4 ms 3456 KB Output is correct
46 Correct 5 ms 3456 KB Output is correct
47 Correct 4 ms 3456 KB Output is correct
48 Correct 5 ms 3456 KB Output is correct
49 Correct 4 ms 3456 KB Output is correct
50 Correct 5 ms 3456 KB Output is correct
51 Correct 4 ms 3456 KB Output is correct
52 Correct 4 ms 3584 KB Output is correct
53 Correct 4 ms 3456 KB Output is correct
54 Correct 4 ms 3456 KB Output is correct
55 Correct 190 ms 6760 KB Output is correct
56 Correct 371 ms 7480 KB Output is correct
57 Correct 185 ms 7524 KB Output is correct
58 Correct 156 ms 6748 KB Output is correct
59 Correct 222 ms 6636 KB Output is correct
60 Correct 288 ms 6896 KB Output is correct
61 Correct 219 ms 6636 KB Output is correct
62 Correct 258 ms 6760 KB Output is correct
63 Correct 162 ms 6260 KB Output is correct
64 Correct 238 ms 6636 KB Output is correct
65 Correct 287 ms 6760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 2 ms 3456 KB Output is correct
8 Correct 2 ms 3456 KB Output is correct
9 Correct 2 ms 3456 KB Output is correct
10 Correct 2 ms 3456 KB Output is correct
11 Correct 3 ms 3456 KB Output is correct
12 Correct 2 ms 3456 KB Output is correct
13 Correct 4 ms 3456 KB Output is correct
14 Correct 2 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 2 ms 3456 KB Output is correct
17 Correct 2 ms 3456 KB Output is correct
18 Correct 2 ms 3456 KB Output is correct
19 Correct 2 ms 3456 KB Output is correct
20 Correct 2 ms 3456 KB Output is correct
21 Correct 2 ms 3456 KB Output is correct
22 Correct 2 ms 3456 KB Output is correct
23 Correct 2 ms 3456 KB Output is correct
24 Correct 2 ms 3456 KB Output is correct
25 Correct 2 ms 3456 KB Output is correct
26 Correct 2 ms 3456 KB Output is correct
27 Correct 2 ms 3456 KB Output is correct
28 Correct 2 ms 3456 KB Output is correct
29 Correct 4 ms 3456 KB Output is correct
30 Correct 4 ms 3456 KB Output is correct
31 Correct 4 ms 3456 KB Output is correct
32 Correct 5 ms 3456 KB Output is correct
33 Correct 4 ms 3456 KB Output is correct
34 Correct 5 ms 3456 KB Output is correct
35 Correct 5 ms 3456 KB Output is correct
36 Correct 4 ms 3456 KB Output is correct
37 Correct 6 ms 3456 KB Output is correct
38 Correct 6 ms 3584 KB Output is correct
39 Correct 4 ms 3456 KB Output is correct
40 Correct 5 ms 3456 KB Output is correct
41 Correct 4 ms 3456 KB Output is correct
42 Correct 4 ms 3456 KB Output is correct
43 Correct 4 ms 3456 KB Output is correct
44 Correct 4 ms 3456 KB Output is correct
45 Correct 4 ms 3456 KB Output is correct
46 Correct 5 ms 3456 KB Output is correct
47 Correct 4 ms 3456 KB Output is correct
48 Correct 5 ms 3456 KB Output is correct
49 Correct 4 ms 3456 KB Output is correct
50 Correct 5 ms 3456 KB Output is correct
51 Correct 4 ms 3456 KB Output is correct
52 Correct 4 ms 3584 KB Output is correct
53 Correct 4 ms 3456 KB Output is correct
54 Correct 4 ms 3456 KB Output is correct
55 Correct 237 ms 7404 KB Output is correct
56 Correct 513 ms 8200 KB Output is correct
57 Correct 273 ms 8036 KB Output is correct
58 Correct 214 ms 7400 KB Output is correct
59 Correct 228 ms 7404 KB Output is correct
60 Correct 226 ms 7280 KB Output is correct
61 Correct 265 ms 7404 KB Output is correct
62 Correct 359 ms 7492 KB Output is correct
63 Correct 268 ms 7404 KB Output is correct
64 Correct 309 ms 7400 KB Output is correct
65 Correct 210 ms 6772 KB Output is correct
66 Correct 218 ms 7024 KB Output is correct
67 Correct 311 ms 7272 KB Output is correct
68 Correct 338 ms 7404 KB Output is correct
69 Correct 244 ms 7528 KB Output is correct
70 Correct 429 ms 8036 KB Output is correct
71 Correct 372 ms 8164 KB Output is correct
72 Correct 198 ms 7532 KB Output is correct
73 Correct 205 ms 7428 KB Output is correct
74 Correct 278 ms 7536 KB Output is correct
75 Correct 351 ms 7512 KB Output is correct
76 Correct 251 ms 7272 KB Output is correct
77 Correct 262 ms 7276 KB Output is correct
78 Correct 303 ms 7412 KB Output is correct
79 Correct 220 ms 6772 KB Output is correct
80 Correct 268 ms 7144 KB Output is correct
81 Correct 317 ms 7532 KB Output is correct
82 Correct 360 ms 7404 KB Output is correct
83 Correct 190 ms 6760 KB Output is correct
84 Correct 371 ms 7480 KB Output is correct
85 Correct 185 ms 7524 KB Output is correct
86 Correct 156 ms 6748 KB Output is correct
87 Correct 222 ms 6636 KB Output is correct
88 Correct 288 ms 6896 KB Output is correct
89 Correct 219 ms 6636 KB Output is correct
90 Correct 258 ms 6760 KB Output is correct
91 Correct 162 ms 6260 KB Output is correct
92 Correct 238 ms 6636 KB Output is correct
93 Correct 287 ms 6760 KB Output is correct
94 Correct 255 ms 7404 KB Output is correct
95 Correct 345 ms 8164 KB Output is correct
96 Correct 241 ms 8048 KB Output is correct
97 Correct 213 ms 7508 KB Output is correct
98 Correct 230 ms 7460 KB Output is correct
99 Correct 250 ms 7152 KB Output is correct
100 Correct 313 ms 7532 KB Output is correct
101 Correct 252 ms 7276 KB Output is correct
102 Correct 287 ms 7404 KB Output is correct
103 Correct 323 ms 7528 KB Output is correct
104 Correct 236 ms 7024 KB Output is correct
105 Correct 309 ms 7336 KB Output is correct
106 Correct 344 ms 7400 KB Output is correct
107 Correct 195 ms 8156 KB Output is correct
108 Correct 252 ms 7404 KB Output is correct
109 Correct 266 ms 7400 KB Output is correct
110 Correct 261 ms 7400 KB Output is correct
111 Correct 251 ms 7272 KB Output is correct
112 Correct 257 ms 7400 KB Output is correct
113 Correct 253 ms 7400 KB Output is correct
114 Correct 256 ms 7400 KB Output is correct
115 Correct 263 ms 7328 KB Output is correct
116 Correct 257 ms 7276 KB Output is correct