Submission #858303

# Submission time Handle Problem Language Result Execution time Memory
858303 2023-10-08T05:32:25 Z Trisanu_Das Joker (BOI20_joker) C++17
100 / 100
395 ms 19072 KB
#include<bits/stdc++.h>
#define Mp make_pair
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
const ll MXN = 2e5 + 10;
ll n, m, q;
ll Par[MXN], Sz[MXN], xr[MXN];
ll from[MXN], to[MXN], dp[MXN];
bool bip = true;
vector<pll> hist;
pll Find(ll x){
    if(Par[x] == x) return Mp(x, xr[x]);
    pll nw = Find(Par[x]);
    nw.second ^=  xr[x];
    return nw;
}
void Union(ll x, ll y){
    pll X = Find(x), Y = Find(y);
    if(X.first == Y.first){
        hist.push_back({-1, bip});
        if(X.second == Y.second) bip = 0;
        return;
    }
    if(Sz[X.first] < Sz[Y.first]) swap(X, Y);
    xr[Y.first] = 1LL ^ X.second ^ Y.second;
    Par[Y.first] = X.first, Sz[X.first] += Sz[Y.first];
    hist.push_back({X.first, Y.first});
}
void Undo(){
    ll x, y; tie(x, y) = hist.back(); hist.pop_back();
    if(x == -1){
        bip = y; return;
    }
    xr[y] = 0, Par[y] = y, Sz[x] -= Sz[y];
}
inline void add_edge(ll i){
    Union(from[i], to[i]);
}
void solve(ll l, ll r, ll opl, ll opr){ // [1, l - 1] + [opr + 1, m]
    if(r < l) return;
    ll mid = (l + r) / 2, opt = -1, tun = 0;
    dp[mid] = m + 1;
    for(int i = l; i < mid; i ++) add_edge(i), tun ++;
    for(int i = opr; i >= max(opl, mid); i --) add_edge(i), tun ++;
    if(bip) dp[mid] = max(opl, mid) - 1;
    else{
        for(int i = max(opl, mid); i <= opr; i ++){
            Undo(); tun --;
            if(bip){
                dp[mid] = i;
                while(tun) Undo(), tun --;
                break;
            }
        }
    }
    opt = min(dp[mid], m);
    while(tun) Undo(), tun --;
    for(int i = l; i <= mid; i ++) add_edge(i), tun ++;
    solve(mid + 1, r, opt, opr);
    while(tun) Undo(), tun --;
    for(int i = opt + 1; i <= opr; i ++) add_edge(i), tun ++;
    solve(l, mid - 1, opl, opt);
    while(tun) Undo(), tun --;
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n >> m >> q;
    for(int i = 1; i <= n; i ++) Par[i] = i, Sz[i] = 1;
    for(int i = 1; i <= m; i ++) cin >> from[i] >> to[i];
    solve(1, m, 1, m);
    while(q --){
        ll l, r; cin >> l >> r;
        cout << (dp[l] <= r ? "NO" : "YES") << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8792 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8660 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8536 KB Output is correct
24 Correct 1 ms 8536 KB Output is correct
25 Correct 1 ms 8536 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8792 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8660 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8536 KB Output is correct
24 Correct 1 ms 8536 KB Output is correct
25 Correct 1 ms 8536 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 2 ms 8536 KB Output is correct
30 Correct 3 ms 8540 KB Output is correct
31 Correct 3 ms 8540 KB Output is correct
32 Correct 3 ms 8540 KB Output is correct
33 Correct 3 ms 8540 KB Output is correct
34 Correct 3 ms 8540 KB Output is correct
35 Correct 3 ms 8540 KB Output is correct
36 Correct 3 ms 8536 KB Output is correct
37 Correct 2 ms 8536 KB Output is correct
38 Correct 2 ms 8540 KB Output is correct
39 Correct 2 ms 8540 KB Output is correct
40 Correct 3 ms 8540 KB Output is correct
41 Correct 3 ms 8536 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 3 ms 8672 KB Output is correct
44 Correct 3 ms 8736 KB Output is correct
45 Correct 3 ms 8540 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 3 ms 8752 KB Output is correct
48 Correct 3 ms 8540 KB Output is correct
49 Correct 3 ms 8540 KB Output is correct
50 Correct 3 ms 8540 KB Output is correct
51 Correct 3 ms 8536 KB Output is correct
52 Correct 4 ms 8540 KB Output is correct
53 Correct 3 ms 8540 KB Output is correct
54 Correct 3 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 207 ms 13868 KB Output is correct
4 Correct 206 ms 14292 KB Output is correct
5 Correct 228 ms 15264 KB Output is correct
6 Correct 274 ms 14648 KB Output is correct
7 Correct 291 ms 14024 KB Output is correct
8 Correct 329 ms 13004 KB Output is correct
9 Correct 338 ms 13364 KB Output is correct
10 Correct 359 ms 14028 KB Output is correct
11 Correct 281 ms 13268 KB Output is correct
12 Correct 302 ms 13728 KB Output is correct
13 Correct 304 ms 13512 KB Output is correct
14 Correct 334 ms 14028 KB Output is correct
15 Correct 363 ms 14792 KB Output is correct
16 Correct 367 ms 14536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8792 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8660 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8536 KB Output is correct
24 Correct 1 ms 8536 KB Output is correct
25 Correct 1 ms 8536 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 207 ms 13868 KB Output is correct
30 Correct 206 ms 14292 KB Output is correct
31 Correct 228 ms 15264 KB Output is correct
32 Correct 274 ms 14648 KB Output is correct
33 Correct 291 ms 14024 KB Output is correct
34 Correct 329 ms 13004 KB Output is correct
35 Correct 338 ms 13364 KB Output is correct
36 Correct 359 ms 14028 KB Output is correct
37 Correct 281 ms 13268 KB Output is correct
38 Correct 302 ms 13728 KB Output is correct
39 Correct 304 ms 13512 KB Output is correct
40 Correct 334 ms 14028 KB Output is correct
41 Correct 363 ms 14792 KB Output is correct
42 Correct 367 ms 14536 KB Output is correct
43 Correct 209 ms 13512 KB Output is correct
44 Correct 208 ms 17680 KB Output is correct
45 Correct 243 ms 17912 KB Output is correct
46 Correct 273 ms 17868 KB Output is correct
47 Correct 303 ms 17860 KB Output is correct
48 Correct 349 ms 16892 KB Output is correct
49 Correct 368 ms 17916 KB Output is correct
50 Correct 288 ms 16832 KB Output is correct
51 Correct 304 ms 17456 KB Output is correct
52 Correct 304 ms 18152 KB Output is correct
53 Correct 326 ms 16788 KB Output is correct
54 Correct 353 ms 17512 KB Output is correct
55 Correct 395 ms 17824 KB Output is correct
56 Correct 362 ms 17912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8792 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8660 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8536 KB Output is correct
24 Correct 1 ms 8536 KB Output is correct
25 Correct 1 ms 8536 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 2 ms 8536 KB Output is correct
30 Correct 3 ms 8540 KB Output is correct
31 Correct 3 ms 8540 KB Output is correct
32 Correct 3 ms 8540 KB Output is correct
33 Correct 3 ms 8540 KB Output is correct
34 Correct 3 ms 8540 KB Output is correct
35 Correct 3 ms 8540 KB Output is correct
36 Correct 3 ms 8536 KB Output is correct
37 Correct 2 ms 8536 KB Output is correct
38 Correct 2 ms 8540 KB Output is correct
39 Correct 2 ms 8540 KB Output is correct
40 Correct 3 ms 8540 KB Output is correct
41 Correct 3 ms 8536 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 3 ms 8672 KB Output is correct
44 Correct 3 ms 8736 KB Output is correct
45 Correct 3 ms 8540 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 3 ms 8752 KB Output is correct
48 Correct 3 ms 8540 KB Output is correct
49 Correct 3 ms 8540 KB Output is correct
50 Correct 3 ms 8540 KB Output is correct
51 Correct 3 ms 8536 KB Output is correct
52 Correct 4 ms 8540 KB Output is correct
53 Correct 3 ms 8540 KB Output is correct
54 Correct 3 ms 8540 KB Output is correct
55 Correct 180 ms 14036 KB Output is correct
56 Correct 178 ms 18256 KB Output is correct
57 Correct 198 ms 17560 KB Output is correct
58 Correct 252 ms 16552 KB Output is correct
59 Correct 326 ms 16332 KB Output is correct
60 Correct 348 ms 17864 KB Output is correct
61 Correct 264 ms 15820 KB Output is correct
62 Correct 267 ms 16668 KB Output is correct
63 Correct 288 ms 15816 KB Output is correct
64 Correct 332 ms 15820 KB Output is correct
65 Correct 347 ms 16332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8792 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8660 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8536 KB Output is correct
24 Correct 1 ms 8536 KB Output is correct
25 Correct 1 ms 8536 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 2 ms 8536 KB Output is correct
30 Correct 3 ms 8540 KB Output is correct
31 Correct 3 ms 8540 KB Output is correct
32 Correct 3 ms 8540 KB Output is correct
33 Correct 3 ms 8540 KB Output is correct
34 Correct 3 ms 8540 KB Output is correct
35 Correct 3 ms 8540 KB Output is correct
36 Correct 3 ms 8536 KB Output is correct
37 Correct 2 ms 8536 KB Output is correct
38 Correct 2 ms 8540 KB Output is correct
39 Correct 2 ms 8540 KB Output is correct
40 Correct 3 ms 8540 KB Output is correct
41 Correct 3 ms 8536 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 3 ms 8672 KB Output is correct
44 Correct 3 ms 8736 KB Output is correct
45 Correct 3 ms 8540 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 3 ms 8752 KB Output is correct
48 Correct 3 ms 8540 KB Output is correct
49 Correct 3 ms 8540 KB Output is correct
50 Correct 3 ms 8540 KB Output is correct
51 Correct 3 ms 8536 KB Output is correct
52 Correct 4 ms 8540 KB Output is correct
53 Correct 3 ms 8540 KB Output is correct
54 Correct 3 ms 8540 KB Output is correct
55 Correct 207 ms 13868 KB Output is correct
56 Correct 206 ms 14292 KB Output is correct
57 Correct 228 ms 15264 KB Output is correct
58 Correct 274 ms 14648 KB Output is correct
59 Correct 291 ms 14024 KB Output is correct
60 Correct 329 ms 13004 KB Output is correct
61 Correct 338 ms 13364 KB Output is correct
62 Correct 359 ms 14028 KB Output is correct
63 Correct 281 ms 13268 KB Output is correct
64 Correct 302 ms 13728 KB Output is correct
65 Correct 304 ms 13512 KB Output is correct
66 Correct 334 ms 14028 KB Output is correct
67 Correct 363 ms 14792 KB Output is correct
68 Correct 367 ms 14536 KB Output is correct
69 Correct 209 ms 13512 KB Output is correct
70 Correct 208 ms 17680 KB Output is correct
71 Correct 243 ms 17912 KB Output is correct
72 Correct 273 ms 17868 KB Output is correct
73 Correct 303 ms 17860 KB Output is correct
74 Correct 349 ms 16892 KB Output is correct
75 Correct 368 ms 17916 KB Output is correct
76 Correct 288 ms 16832 KB Output is correct
77 Correct 304 ms 17456 KB Output is correct
78 Correct 304 ms 18152 KB Output is correct
79 Correct 326 ms 16788 KB Output is correct
80 Correct 353 ms 17512 KB Output is correct
81 Correct 395 ms 17824 KB Output is correct
82 Correct 362 ms 17912 KB Output is correct
83 Correct 180 ms 14036 KB Output is correct
84 Correct 178 ms 18256 KB Output is correct
85 Correct 198 ms 17560 KB Output is correct
86 Correct 252 ms 16552 KB Output is correct
87 Correct 326 ms 16332 KB Output is correct
88 Correct 348 ms 17864 KB Output is correct
89 Correct 264 ms 15820 KB Output is correct
90 Correct 267 ms 16668 KB Output is correct
91 Correct 288 ms 15816 KB Output is correct
92 Correct 332 ms 15820 KB Output is correct
93 Correct 347 ms 16332 KB Output is correct
94 Correct 208 ms 17816 KB Output is correct
95 Correct 232 ms 18684 KB Output is correct
96 Correct 236 ms 18920 KB Output is correct
97 Correct 281 ms 17856 KB Output is correct
98 Correct 300 ms 17856 KB Output is correct
99 Correct 339 ms 17600 KB Output is correct
100 Correct 349 ms 18860 KB Output is correct
101 Correct 291 ms 17856 KB Output is correct
102 Correct 312 ms 18904 KB Output is correct
103 Correct 315 ms 18856 KB Output is correct
104 Correct 333 ms 17656 KB Output is correct
105 Correct 365 ms 18116 KB Output is correct
106 Correct 386 ms 18788 KB Output is correct
107 Correct 172 ms 19072 KB Output is correct
108 Correct 207 ms 17644 KB Output is correct
109 Correct 210 ms 18184 KB Output is correct
110 Correct 205 ms 18196 KB Output is correct
111 Correct 208 ms 17608 KB Output is correct
112 Correct 206 ms 18268 KB Output is correct
113 Correct 204 ms 17776 KB Output is correct
114 Correct 211 ms 17860 KB Output is correct
115 Correct 211 ms 18328 KB Output is correct
116 Correct 205 ms 17528 KB Output is correct