답안 #560102

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
560102 2022-05-11T04:13:08 Z abcvuitunggio Joker (BOI20_joker) C++17
100 / 100
199 ms 13368 KB
#include <iostream>
#include <vector>
using namespace std;
struct state{
    int u,pu,v,pv;
};
int n,m,t,p[200001],f[200001],d[200001],a[200001],b[200001],l,r;
vector <state> q;
pair <int, int> findp(int i){
    int x=0;
    while (p[i]!=i){
        x^=f[i];
        i=p[i];
    }
    return {i,x};
}
bool unite(int i, int j){
    auto pi=findp(i),pj=findp(j);
    if (pi.first==pj.first)
        return (pi.second!=pj.second);
    q.push_back({pi.first,pi.first,pj.first,pj.first});
    if (pi.first>pj.first)
        swap(pi,pj);
    p[pi.first]=pj.first;
    f[pi.first]=pi.second^pj.second^1;
    return true;
}
void rollback(int sz){
    while (q.size()>sz){
        state s=q.back();
        q.pop_back();
        p[s.u]=s.pu;
        p[s.v]=s.pv;
    }
}
void cal(int l, int r, int optl, int optr){
    if (l>r)
        return;
    int mid=(l+r)>>1,ch=1;
    int s=q.size();
    for (int i=max(l,1);i<=mid;i++)
        if (!unite(a[i],b[i])){
            ch=0;
            break;
        }
    if (ch){
        int s2=q.size();
        d[mid]=0;
        for (int i=min(optr,m);i>=max(optl,mid+1);i--)
            if (!unite(a[i],b[i])){
                d[mid]=i;
                break;
            }

        rollback(s2);
        cal(mid+1,r,d[mid],optr);
    }
    rollback(s);
    for (int i=d[mid]+1;i<=optr;i++)
        unite(a[i],b[i]);
    cal(l,mid-1,optl,d[mid]);
    rollback(s);
}
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n >> m >> t;
    for (int i=1;i<=n;i++)
        p[i]=i;
    for (int i=1;i<=m;i++){
        cin >> a[i] >> b[i];
        d[i]=m+1;
    }
    cal(0,m,1,m+1);
    while (t--){
        cin >> l >> r;
        cout << (d[l-1]>=r+1?"YES\n":"NO\n");
    }
}

Compilation message

Joker.cpp: In function 'void rollback(int)':
Joker.cpp:29:20: warning: comparison of integer expressions of different signedness: 'std::vector<state>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     while (q.size()>sz){
      |            ~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 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 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 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 332 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 328 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 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 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 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 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 332 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 328 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 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 400 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 3 ms 340 KB Output is correct
41 Correct 2 ms 336 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 344 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 3 ms 344 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 472 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 1 ms 400 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 2 ms 404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 134 ms 9732 KB Output is correct
4 Correct 122 ms 11624 KB Output is correct
5 Correct 116 ms 11796 KB Output is correct
6 Correct 113 ms 9708 KB Output is correct
7 Correct 112 ms 9776 KB Output is correct
8 Correct 126 ms 8276 KB Output is correct
9 Correct 158 ms 9024 KB Output is correct
10 Correct 163 ms 10320 KB Output is correct
11 Correct 175 ms 9396 KB Output is correct
12 Correct 174 ms 10560 KB Output is correct
13 Correct 159 ms 7752 KB Output is correct
14 Correct 136 ms 8780 KB Output is correct
15 Correct 179 ms 9992 KB Output is correct
16 Correct 176 ms 10696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 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 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 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 332 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 328 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 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 134 ms 9732 KB Output is correct
30 Correct 122 ms 11624 KB Output is correct
31 Correct 116 ms 11796 KB Output is correct
32 Correct 113 ms 9708 KB Output is correct
33 Correct 112 ms 9776 KB Output is correct
34 Correct 126 ms 8276 KB Output is correct
35 Correct 158 ms 9024 KB Output is correct
36 Correct 163 ms 10320 KB Output is correct
37 Correct 175 ms 9396 KB Output is correct
38 Correct 174 ms 10560 KB Output is correct
39 Correct 159 ms 7752 KB Output is correct
40 Correct 136 ms 8780 KB Output is correct
41 Correct 179 ms 9992 KB Output is correct
42 Correct 176 ms 10696 KB Output is correct
43 Correct 145 ms 9992 KB Output is correct
44 Correct 131 ms 12052 KB Output is correct
45 Correct 199 ms 12432 KB Output is correct
46 Correct 123 ms 10096 KB Output is correct
47 Correct 114 ms 10176 KB Output is correct
48 Correct 172 ms 9508 KB Output is correct
49 Correct 185 ms 10828 KB Output is correct
50 Correct 147 ms 9584 KB Output is correct
51 Correct 148 ms 10412 KB Output is correct
52 Correct 163 ms 11028 KB Output is correct
53 Correct 148 ms 7976 KB Output is correct
54 Correct 184 ms 9556 KB Output is correct
55 Correct 170 ms 10396 KB Output is correct
56 Correct 176 ms 10988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 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 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 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 332 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 328 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 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 400 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 3 ms 340 KB Output is correct
41 Correct 2 ms 336 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 344 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 3 ms 344 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 472 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 1 ms 400 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 2 ms 404 KB Output is correct
55 Correct 98 ms 7972 KB Output is correct
56 Correct 101 ms 10996 KB Output is correct
57 Correct 90 ms 10816 KB Output is correct
58 Correct 71 ms 7868 KB Output is correct
59 Correct 128 ms 7860 KB Output is correct
60 Correct 155 ms 8612 KB Output is correct
61 Correct 113 ms 7880 KB Output is correct
62 Correct 138 ms 8772 KB Output is correct
63 Correct 119 ms 6368 KB Output is correct
64 Correct 120 ms 8156 KB Output is correct
65 Correct 160 ms 8776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 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 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 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 332 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 328 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 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 400 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 3 ms 340 KB Output is correct
41 Correct 2 ms 336 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 344 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 3 ms 344 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 472 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 1 ms 400 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 2 ms 404 KB Output is correct
55 Correct 134 ms 9732 KB Output is correct
56 Correct 122 ms 11624 KB Output is correct
57 Correct 116 ms 11796 KB Output is correct
58 Correct 113 ms 9708 KB Output is correct
59 Correct 112 ms 9776 KB Output is correct
60 Correct 126 ms 8276 KB Output is correct
61 Correct 158 ms 9024 KB Output is correct
62 Correct 163 ms 10320 KB Output is correct
63 Correct 175 ms 9396 KB Output is correct
64 Correct 174 ms 10560 KB Output is correct
65 Correct 159 ms 7752 KB Output is correct
66 Correct 136 ms 8780 KB Output is correct
67 Correct 179 ms 9992 KB Output is correct
68 Correct 176 ms 10696 KB Output is correct
69 Correct 145 ms 9992 KB Output is correct
70 Correct 131 ms 12052 KB Output is correct
71 Correct 199 ms 12432 KB Output is correct
72 Correct 123 ms 10096 KB Output is correct
73 Correct 114 ms 10176 KB Output is correct
74 Correct 172 ms 9508 KB Output is correct
75 Correct 185 ms 10828 KB Output is correct
76 Correct 147 ms 9584 KB Output is correct
77 Correct 148 ms 10412 KB Output is correct
78 Correct 163 ms 11028 KB Output is correct
79 Correct 148 ms 7976 KB Output is correct
80 Correct 184 ms 9556 KB Output is correct
81 Correct 170 ms 10396 KB Output is correct
82 Correct 176 ms 10988 KB Output is correct
83 Correct 98 ms 7972 KB Output is correct
84 Correct 101 ms 10996 KB Output is correct
85 Correct 90 ms 10816 KB Output is correct
86 Correct 71 ms 7868 KB Output is correct
87 Correct 128 ms 7860 KB Output is correct
88 Correct 155 ms 8612 KB Output is correct
89 Correct 113 ms 7880 KB Output is correct
90 Correct 138 ms 8772 KB Output is correct
91 Correct 119 ms 6368 KB Output is correct
92 Correct 120 ms 8156 KB Output is correct
93 Correct 160 ms 8776 KB Output is correct
94 Correct 143 ms 10800 KB Output is correct
95 Correct 160 ms 13096 KB Output is correct
96 Correct 123 ms 12828 KB Output is correct
97 Correct 114 ms 10772 KB Output is correct
98 Correct 116 ms 10792 KB Output is correct
99 Correct 156 ms 9796 KB Output is correct
100 Correct 154 ms 11752 KB Output is correct
101 Correct 140 ms 10336 KB Output is correct
102 Correct 180 ms 11112 KB Output is correct
103 Correct 195 ms 12032 KB Output is correct
104 Correct 152 ms 9312 KB Output is correct
105 Correct 180 ms 10816 KB Output is correct
106 Correct 181 ms 11532 KB Output is correct
107 Correct 130 ms 13368 KB Output is correct
108 Correct 139 ms 10484 KB Output is correct
109 Correct 137 ms 10608 KB Output is correct
110 Correct 136 ms 10520 KB Output is correct
111 Correct 132 ms 10528 KB Output is correct
112 Correct 135 ms 10564 KB Output is correct
113 Correct 130 ms 10540 KB Output is correct
114 Correct 161 ms 10544 KB Output is correct
115 Correct 144 ms 10560 KB Output is correct
116 Correct 154 ms 10560 KB Output is correct