답안 #443328

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
443328 2021-07-10T11:09:35 Z Nima_Naderi Joker (BOI20_joker) C++14
100 / 100
960 ms 18880 KB
///In the name of GOD
//#pragma GCC optimize("O2")
#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;
}
/*!
    HE'S AN INSTIGATOR,
    ENEMY ELIMINATOR,
    AND WHEN HE KNOCKS YOU BETTER
    YOU BETTER LET HIM IN.
*/
//! N.N
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 316 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 5 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 5 ms 320 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 316 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 5 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 5 ms 320 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 476 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 17 ms 520 KB Output is correct
33 Correct 4 ms 460 KB Output is correct
34 Correct 5 ms 460 KB Output is correct
35 Correct 5 ms 460 KB Output is correct
36 Correct 3 ms 460 KB Output is correct
37 Correct 4 ms 460 KB Output is correct
38 Correct 3 ms 460 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 4 ms 460 KB Output is correct
41 Correct 3 ms 456 KB Output is correct
42 Correct 3 ms 460 KB Output is correct
43 Correct 3 ms 460 KB Output is correct
44 Correct 4 ms 460 KB Output is correct
45 Correct 4 ms 460 KB Output is correct
46 Correct 4 ms 460 KB Output is correct
47 Correct 3 ms 460 KB Output is correct
48 Correct 3 ms 520 KB Output is correct
49 Correct 6 ms 460 KB Output is correct
50 Correct 4 ms 460 KB Output is correct
51 Correct 3 ms 460 KB Output is correct
52 Correct 3 ms 460 KB Output is correct
53 Correct 4 ms 460 KB Output is correct
54 Correct 4 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 412 ms 15292 KB Output is correct
4 Correct 465 ms 17168 KB Output is correct
5 Correct 572 ms 17328 KB Output is correct
6 Correct 494 ms 15264 KB Output is correct
7 Correct 557 ms 15240 KB Output is correct
8 Correct 652 ms 13716 KB Output is correct
9 Correct 620 ms 14868 KB Output is correct
10 Correct 821 ms 17184 KB Output is correct
11 Correct 523 ms 15120 KB Output is correct
12 Correct 555 ms 17188 KB Output is correct
13 Correct 492 ms 13292 KB Output is correct
14 Correct 574 ms 14304 KB Output is correct
15 Correct 758 ms 16176 KB Output is correct
16 Correct 833 ms 17692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 316 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 5 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 5 ms 320 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 412 ms 15292 KB Output is correct
30 Correct 465 ms 17168 KB Output is correct
31 Correct 572 ms 17328 KB Output is correct
32 Correct 494 ms 15264 KB Output is correct
33 Correct 557 ms 15240 KB Output is correct
34 Correct 652 ms 13716 KB Output is correct
35 Correct 620 ms 14868 KB Output is correct
36 Correct 821 ms 17184 KB Output is correct
37 Correct 523 ms 15120 KB Output is correct
38 Correct 555 ms 17188 KB Output is correct
39 Correct 492 ms 13292 KB Output is correct
40 Correct 574 ms 14304 KB Output is correct
41 Correct 758 ms 16176 KB Output is correct
42 Correct 833 ms 17692 KB Output is correct
43 Correct 403 ms 15460 KB Output is correct
44 Correct 442 ms 17508 KB Output is correct
45 Correct 677 ms 17912 KB Output is correct
46 Correct 498 ms 15496 KB Output is correct
47 Correct 517 ms 15616 KB Output is correct
48 Correct 703 ms 15220 KB Output is correct
49 Correct 943 ms 17696 KB Output is correct
50 Correct 492 ms 14956 KB Output is correct
51 Correct 549 ms 16568 KB Output is correct
52 Correct 796 ms 17880 KB Output is correct
53 Correct 487 ms 13488 KB Output is correct
54 Correct 650 ms 15096 KB Output is correct
55 Correct 863 ms 16596 KB Output is correct
56 Correct 900 ms 18092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 316 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 5 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 5 ms 320 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 476 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 17 ms 520 KB Output is correct
33 Correct 4 ms 460 KB Output is correct
34 Correct 5 ms 460 KB Output is correct
35 Correct 5 ms 460 KB Output is correct
36 Correct 3 ms 460 KB Output is correct
37 Correct 4 ms 460 KB Output is correct
38 Correct 3 ms 460 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 4 ms 460 KB Output is correct
41 Correct 3 ms 456 KB Output is correct
42 Correct 3 ms 460 KB Output is correct
43 Correct 3 ms 460 KB Output is correct
44 Correct 4 ms 460 KB Output is correct
45 Correct 4 ms 460 KB Output is correct
46 Correct 4 ms 460 KB Output is correct
47 Correct 3 ms 460 KB Output is correct
48 Correct 3 ms 520 KB Output is correct
49 Correct 6 ms 460 KB Output is correct
50 Correct 4 ms 460 KB Output is correct
51 Correct 3 ms 460 KB Output is correct
52 Correct 3 ms 460 KB Output is correct
53 Correct 4 ms 460 KB Output is correct
54 Correct 4 ms 464 KB Output is correct
55 Correct 333 ms 12968 KB Output is correct
56 Correct 451 ms 15568 KB Output is correct
57 Correct 467 ms 14996 KB Output is correct
58 Correct 422 ms 12976 KB Output is correct
59 Correct 653 ms 12900 KB Output is correct
60 Correct 685 ms 14440 KB Output is correct
61 Correct 448 ms 12912 KB Output is correct
62 Correct 960 ms 15132 KB Output is correct
63 Correct 471 ms 11500 KB Output is correct
64 Correct 597 ms 13440 KB Output is correct
65 Correct 745 ms 15048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 316 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 5 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 5 ms 320 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 476 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 17 ms 520 KB Output is correct
33 Correct 4 ms 460 KB Output is correct
34 Correct 5 ms 460 KB Output is correct
35 Correct 5 ms 460 KB Output is correct
36 Correct 3 ms 460 KB Output is correct
37 Correct 4 ms 460 KB Output is correct
38 Correct 3 ms 460 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 4 ms 460 KB Output is correct
41 Correct 3 ms 456 KB Output is correct
42 Correct 3 ms 460 KB Output is correct
43 Correct 3 ms 460 KB Output is correct
44 Correct 4 ms 460 KB Output is correct
45 Correct 4 ms 460 KB Output is correct
46 Correct 4 ms 460 KB Output is correct
47 Correct 3 ms 460 KB Output is correct
48 Correct 3 ms 520 KB Output is correct
49 Correct 6 ms 460 KB Output is correct
50 Correct 4 ms 460 KB Output is correct
51 Correct 3 ms 460 KB Output is correct
52 Correct 3 ms 460 KB Output is correct
53 Correct 4 ms 460 KB Output is correct
54 Correct 4 ms 464 KB Output is correct
55 Correct 412 ms 15292 KB Output is correct
56 Correct 465 ms 17168 KB Output is correct
57 Correct 572 ms 17328 KB Output is correct
58 Correct 494 ms 15264 KB Output is correct
59 Correct 557 ms 15240 KB Output is correct
60 Correct 652 ms 13716 KB Output is correct
61 Correct 620 ms 14868 KB Output is correct
62 Correct 821 ms 17184 KB Output is correct
63 Correct 523 ms 15120 KB Output is correct
64 Correct 555 ms 17188 KB Output is correct
65 Correct 492 ms 13292 KB Output is correct
66 Correct 574 ms 14304 KB Output is correct
67 Correct 758 ms 16176 KB Output is correct
68 Correct 833 ms 17692 KB Output is correct
69 Correct 403 ms 15460 KB Output is correct
70 Correct 442 ms 17508 KB Output is correct
71 Correct 677 ms 17912 KB Output is correct
72 Correct 498 ms 15496 KB Output is correct
73 Correct 517 ms 15616 KB Output is correct
74 Correct 703 ms 15220 KB Output is correct
75 Correct 943 ms 17696 KB Output is correct
76 Correct 492 ms 14956 KB Output is correct
77 Correct 549 ms 16568 KB Output is correct
78 Correct 796 ms 17880 KB Output is correct
79 Correct 487 ms 13488 KB Output is correct
80 Correct 650 ms 15096 KB Output is correct
81 Correct 863 ms 16596 KB Output is correct
82 Correct 900 ms 18092 KB Output is correct
83 Correct 333 ms 12968 KB Output is correct
84 Correct 451 ms 15568 KB Output is correct
85 Correct 467 ms 14996 KB Output is correct
86 Correct 422 ms 12976 KB Output is correct
87 Correct 653 ms 12900 KB Output is correct
88 Correct 685 ms 14440 KB Output is correct
89 Correct 448 ms 12912 KB Output is correct
90 Correct 960 ms 15132 KB Output is correct
91 Correct 471 ms 11500 KB Output is correct
92 Correct 597 ms 13440 KB Output is correct
93 Correct 745 ms 15048 KB Output is correct
94 Correct 490 ms 16288 KB Output is correct
95 Correct 464 ms 18584 KB Output is correct
96 Correct 707 ms 18316 KB Output is correct
97 Correct 590 ms 16276 KB Output is correct
98 Correct 575 ms 16260 KB Output is correct
99 Correct 614 ms 15320 KB Output is correct
100 Correct 831 ms 18820 KB Output is correct
101 Correct 485 ms 16052 KB Output is correct
102 Correct 655 ms 17480 KB Output is correct
103 Correct 638 ms 18800 KB Output is correct
104 Correct 570 ms 14716 KB Output is correct
105 Correct 634 ms 16816 KB Output is correct
106 Correct 833 ms 18344 KB Output is correct
107 Correct 254 ms 18880 KB Output is correct
108 Correct 407 ms 16008 KB Output is correct
109 Correct 378 ms 15972 KB Output is correct
110 Correct 362 ms 16012 KB Output is correct
111 Correct 392 ms 16044 KB Output is correct
112 Correct 399 ms 16052 KB Output is correct
113 Correct 378 ms 16036 KB Output is correct
114 Correct 370 ms 16048 KB Output is correct
115 Correct 421 ms 16020 KB Output is correct
116 Correct 396 ms 15948 KB Output is correct