답안 #948638

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948638 2024-03-18T09:52:55 Z dimashhh Joker (BOI20_joker) C++17
100 / 100
212 ms 17844 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 3e5 + 5, MOD = 998244353;

int p[N],sz[N],n,m,q,d[N];
int cur_col = 0;
void reset(){
    cur_col = 0;
    for(int i = 1;i <= n;i++){
        sz[i] = 1;
        p[i] = i;
        d[i] = 0;
    }
}
pair<int, int> get(int v) {
    if(p[v] == v){
        return {v,0};
    }
    pair<int,int> x = get(p[v]);
    return {x.first,d[v]+x.second};
}
vector<array<int,5>> st;
bool merge(int a,int b){
    pair<int,int> x = get(a),y = get(b);
    if(sz[x.first] < sz[y.first]){
        swap(x,y);
    }
    a = x.first;
    b = y.first;
    if(a == b){
        if(x.second % 2 == y.second % 2){
            st.push_back({a,b,-1,1,0});
            cur_col++;
            return true;
        }
        st.push_back({a,b,-1,0,0});
        return false;
    }
    st.push_back({a,b,sz[a],p[b],d[b]});
    p[b] = a;
    sz[a] += sz[b];
    d[b] = (x.second % 2 == y.second % 2);
    return false;
}
queue<array<int,4>> qr;
void roll_back(){
    auto dd = st.back();
    st.pop_back();
    if(dd[2] == -1){
        cur_col -= dd[3];
        return;
    }
    sz[dd[0]] = dd[2];
    p[dd[1]] = dd[3];
    d[dd[1]] = dd[4];
}
int x[N],y[N],R[N];
void go(int l,int r,int _l,int _r){
    if(l > r) return;
    int t = (l + r) >> 1;
    int c = 0,c1 = 0;
    for(int i = l;i < t;++i){
        merge(x[i],y[i]);
    }
    R[t] = _r;
    while(R[t] >= t && cur_col == 0){
        c1++;
        merge(x[R[t]],y[R[t]]);
        R[t]--;
    }
    for(int i = 0;i < c1;i++){
        roll_back();
    }
    merge(x[t],y[t]);
    go(t+1,r,R[t],_r);
    for(int i = l;i <= t;i++){
        roll_back();
    }
    for(int i = _r;i > R[t];i--){
        merge(x[i],y[i]);
    }
    go(l,t-1,_l,R[t]);
    for(int i = 0;i < c1;i++){
        roll_back();
    }
}
void test(){
    cin >> n >> m >> q;
    for(int i = 1;i <= m;i++){
        cin >> x[i] >> y[i];
    }
    reset();
    go(1,m,1,m);
    for(int i =1 ;i <= m;i++){
        R[i]++;
    }
    for(int i = 1;i <= q;i++){
        int l,r;
        cin >> l >> r;
        cout << (r < R[l] ? "YES\n":"NO\n");
    }
}
/*
 1 4
2 4
3 7
4 8
5 8
6 8
7 8
8 9
 */
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int T = 1;
//    cin >> T;
    while(T--){
        test();
    }
}

Compilation message

Joker.cpp: In function 'void go(int, int, int, int)':
Joker.cpp:65:9: warning: unused variable 'c' [-Wunused-variable]
   65 |     int c = 0,c1 = 0;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 3 ms 6616 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 2 ms 6488 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6492 KB Output is correct
45 Correct 2 ms 6492 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 3 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6708 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 113 ms 12744 KB Output is correct
4 Correct 176 ms 14472 KB Output is correct
5 Correct 98 ms 15040 KB Output is correct
6 Correct 121 ms 15296 KB Output is correct
7 Correct 119 ms 14644 KB Output is correct
8 Correct 129 ms 14124 KB Output is correct
9 Correct 142 ms 15256 KB Output is correct
10 Correct 174 ms 14888 KB Output is correct
11 Correct 136 ms 14036 KB Output is correct
12 Correct 152 ms 14040 KB Output is correct
13 Correct 154 ms 14144 KB Output is correct
14 Correct 136 ms 14784 KB Output is correct
15 Correct 176 ms 14520 KB Output is correct
16 Correct 175 ms 14704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 113 ms 12744 KB Output is correct
30 Correct 176 ms 14472 KB Output is correct
31 Correct 98 ms 15040 KB Output is correct
32 Correct 121 ms 15296 KB Output is correct
33 Correct 119 ms 14644 KB Output is correct
34 Correct 129 ms 14124 KB Output is correct
35 Correct 142 ms 15256 KB Output is correct
36 Correct 174 ms 14888 KB Output is correct
37 Correct 136 ms 14036 KB Output is correct
38 Correct 152 ms 14040 KB Output is correct
39 Correct 154 ms 14144 KB Output is correct
40 Correct 136 ms 14784 KB Output is correct
41 Correct 176 ms 14520 KB Output is correct
42 Correct 175 ms 14704 KB Output is correct
43 Correct 114 ms 13604 KB Output is correct
44 Correct 176 ms 15224 KB Output is correct
45 Correct 156 ms 15808 KB Output is correct
46 Correct 115 ms 14044 KB Output is correct
47 Correct 121 ms 14020 KB Output is correct
48 Correct 147 ms 13972 KB Output is correct
49 Correct 181 ms 15288 KB Output is correct
50 Correct 141 ms 14276 KB Output is correct
51 Correct 144 ms 15032 KB Output is correct
52 Correct 155 ms 15632 KB Output is correct
53 Correct 141 ms 14520 KB Output is correct
54 Correct 194 ms 14484 KB Output is correct
55 Correct 173 ms 14652 KB Output is correct
56 Correct 177 ms 15404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 3 ms 6616 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 2 ms 6488 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6492 KB Output is correct
45 Correct 2 ms 6492 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 3 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6708 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 89 ms 13512 KB Output is correct
56 Correct 146 ms 16072 KB Output is correct
57 Correct 74 ms 15024 KB Output is correct
58 Correct 94 ms 15296 KB Output is correct
59 Correct 126 ms 14760 KB Output is correct
60 Correct 180 ms 15820 KB Output is correct
61 Correct 120 ms 14796 KB Output is correct
62 Correct 120 ms 16068 KB Output is correct
63 Correct 102 ms 14784 KB Output is correct
64 Correct 143 ms 15564 KB Output is correct
65 Correct 156 ms 15052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 3 ms 6616 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 2 ms 6488 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6492 KB Output is correct
45 Correct 2 ms 6492 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 3 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6708 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 113 ms 12744 KB Output is correct
56 Correct 176 ms 14472 KB Output is correct
57 Correct 98 ms 15040 KB Output is correct
58 Correct 121 ms 15296 KB Output is correct
59 Correct 119 ms 14644 KB Output is correct
60 Correct 129 ms 14124 KB Output is correct
61 Correct 142 ms 15256 KB Output is correct
62 Correct 174 ms 14888 KB Output is correct
63 Correct 136 ms 14036 KB Output is correct
64 Correct 152 ms 14040 KB Output is correct
65 Correct 154 ms 14144 KB Output is correct
66 Correct 136 ms 14784 KB Output is correct
67 Correct 176 ms 14520 KB Output is correct
68 Correct 175 ms 14704 KB Output is correct
69 Correct 114 ms 13604 KB Output is correct
70 Correct 176 ms 15224 KB Output is correct
71 Correct 156 ms 15808 KB Output is correct
72 Correct 115 ms 14044 KB Output is correct
73 Correct 121 ms 14020 KB Output is correct
74 Correct 147 ms 13972 KB Output is correct
75 Correct 181 ms 15288 KB Output is correct
76 Correct 141 ms 14276 KB Output is correct
77 Correct 144 ms 15032 KB Output is correct
78 Correct 155 ms 15632 KB Output is correct
79 Correct 141 ms 14520 KB Output is correct
80 Correct 194 ms 14484 KB Output is correct
81 Correct 173 ms 14652 KB Output is correct
82 Correct 177 ms 15404 KB Output is correct
83 Correct 89 ms 13512 KB Output is correct
84 Correct 146 ms 16072 KB Output is correct
85 Correct 74 ms 15024 KB Output is correct
86 Correct 94 ms 15296 KB Output is correct
87 Correct 126 ms 14760 KB Output is correct
88 Correct 180 ms 15820 KB Output is correct
89 Correct 120 ms 14796 KB Output is correct
90 Correct 120 ms 16068 KB Output is correct
91 Correct 102 ms 14784 KB Output is correct
92 Correct 143 ms 15564 KB Output is correct
93 Correct 156 ms 15052 KB Output is correct
94 Correct 116 ms 16276 KB Output is correct
95 Correct 158 ms 16720 KB Output is correct
96 Correct 102 ms 17844 KB Output is correct
97 Correct 121 ms 16632 KB Output is correct
98 Correct 123 ms 16612 KB Output is correct
99 Correct 143 ms 16268 KB Output is correct
100 Correct 212 ms 16792 KB Output is correct
101 Correct 139 ms 16940 KB Output is correct
102 Correct 155 ms 16452 KB Output is correct
103 Correct 164 ms 17276 KB Output is correct
104 Correct 140 ms 16304 KB Output is correct
105 Correct 179 ms 16708 KB Output is correct
106 Correct 179 ms 16824 KB Output is correct
107 Correct 96 ms 17076 KB Output is correct
108 Correct 114 ms 16056 KB Output is correct
109 Correct 112 ms 16564 KB Output is correct
110 Correct 118 ms 16168 KB Output is correct
111 Correct 118 ms 16052 KB Output is correct
112 Correct 116 ms 16164 KB Output is correct
113 Correct 114 ms 16308 KB Output is correct
114 Correct 116 ms 16052 KB Output is correct
115 Correct 127 ms 16024 KB Output is correct
116 Correct 113 ms 17324 KB Output is correct