Submission #446933

# Submission time Handle Problem Language Result Execution time Memory
446933 2021-07-23T23:49:59 Z Ozy Joker (BOI20_joker) C++17
100 / 100
897 ms 15360 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "

#define MAX 200000
#define val first
#define x second

lli n,m,q,c,d;
lli res[MAX+2],from[MAX+2],to[MAX+2],xr[MAX+2],padres[MAX+2],tam[MAX+2];
lli bip;
stack<pair<lli,lli> > histo;

pair<lli,lli> Find(lli a) {
    if (padres[a] == a) return {a, xr[a]};
    pair<lli,lli> nuevo = Find(padres[a]);
    nuevo.x ^= xr[a];
    return nuevo;
}

void Undo() {
    pair<lli,lli> a = histo.top();
    histo.pop();

    if (a.first == -1) {
        bip = a.second;
        return;
    }
    padres[a.second] = a.second;
    tam[a.first] -= tam[a.second];
    xr[a.second] = 0;
}

void Union(lli a, lli b) {
    pair<lli,lli> A = Find(a);
    pair<lli,lli> B = Find(b);

    if (A.val == B.val) {
        histo.push({-1,bip});
        if (A.x == B.x) bip = 0;
        return;
    }

    if (tam[A.val] < tam[B.val]) swap(A,B);
    xr[B.val] = 1ll ^ A.x ^ B.x;
    padres[B.val] = A.val;
    tam[A.val] += tam[B.val];
    histo.push({A.val, B.val});
}

void DC(lli ini, lli fin, lli l, lli r) {

    if (ini > fin) return;
    lli sum = 0;
    lli op;
    lli mitad = (ini+fin)/2;

    res[mitad] = m+1;
    rep (i,ini,mitad-1) {Union(from[i],to[i]); sum++;}
    repa(i,r,max(mitad,l)) {Union(from[i],to[i]); sum++;}

    if (bip) res[mitad] = max(mitad,l) - 1;
    else {
        rep(i,max(mitad,l),r) {
            Undo();
            sum--;
            if (bip) {
                res[mitad] = i;
                while (sum) {Undo(); sum--;}
                break;
            }
        }
    }

    while (sum) {Undo(); sum--;}
    op = min(res[mitad],m);

    rep(i,ini,mitad) {Union(from[i], to[i]); sum++;}
    DC(mitad+1,fin,op,r);
    while (sum) {Undo(); sum--;}

    rep(i,op+1,r) {Union(from[i], to[i]); sum++;}
    DC(ini,mitad-1,l,op);
    while (sum) {Undo(); sum--;}
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >> q;
    rep(i,1,m) cin >> from[i] >> to[i];

    bip = 1;
    rep(i,1,n) {padres[i] = i; tam[i] = 1;}
    DC(1,m,1,m);

    rep(i,1,q) {
        cin >> c >> d;
        if (res[c] <= d) cout << "NO\n";
        else cout << "YES\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 320 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 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 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 320 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 1 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 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 320 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 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 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 320 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 1 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 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 4 ms 460 KB Output is correct
32 Correct 3 ms 472 KB Output is correct
33 Correct 3 ms 460 KB Output is correct
34 Correct 4 ms 460 KB Output is correct
35 Correct 4 ms 460 KB Output is correct
36 Correct 3 ms 460 KB Output is correct
37 Correct 5 ms 460 KB Output is correct
38 Correct 4 ms 460 KB Output is correct
39 Correct 4 ms 460 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 3 ms 460 KB Output is correct
43 Correct 3 ms 460 KB Output is correct
44 Correct 3 ms 388 KB Output is correct
45 Correct 3 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 396 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 3 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 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 409 ms 11732 KB Output is correct
4 Correct 489 ms 15076 KB Output is correct
5 Correct 540 ms 14052 KB Output is correct
6 Correct 505 ms 12156 KB Output is correct
7 Correct 586 ms 12176 KB Output is correct
8 Correct 602 ms 11896 KB Output is correct
9 Correct 645 ms 12240 KB Output is correct
10 Correct 801 ms 14592 KB Output is correct
11 Correct 528 ms 12732 KB Output is correct
12 Correct 629 ms 14060 KB Output is correct
13 Correct 530 ms 10396 KB Output is correct
14 Correct 619 ms 11800 KB Output is correct
15 Correct 739 ms 13272 KB Output is correct
16 Correct 797 ms 14548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 320 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 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 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 320 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 1 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 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 409 ms 11732 KB Output is correct
30 Correct 489 ms 15076 KB Output is correct
31 Correct 540 ms 14052 KB Output is correct
32 Correct 505 ms 12156 KB Output is correct
33 Correct 586 ms 12176 KB Output is correct
34 Correct 602 ms 11896 KB Output is correct
35 Correct 645 ms 12240 KB Output is correct
36 Correct 801 ms 14592 KB Output is correct
37 Correct 528 ms 12732 KB Output is correct
38 Correct 629 ms 14060 KB Output is correct
39 Correct 530 ms 10396 KB Output is correct
40 Correct 619 ms 11800 KB Output is correct
41 Correct 739 ms 13272 KB Output is correct
42 Correct 797 ms 14548 KB Output is correct
43 Correct 430 ms 12852 KB Output is correct
44 Correct 457 ms 15092 KB Output is correct
45 Correct 640 ms 15128 KB Output is correct
46 Correct 513 ms 12824 KB Output is correct
47 Correct 583 ms 12736 KB Output is correct
48 Correct 748 ms 11748 KB Output is correct
49 Correct 854 ms 14560 KB Output is correct
50 Correct 539 ms 11628 KB Output is correct
51 Correct 579 ms 13692 KB Output is correct
52 Correct 700 ms 13996 KB Output is correct
53 Correct 537 ms 9568 KB Output is correct
54 Correct 675 ms 12316 KB Output is correct
55 Correct 794 ms 12384 KB Output is correct
56 Correct 897 ms 14228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 320 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 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 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 320 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 1 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 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 4 ms 460 KB Output is correct
32 Correct 3 ms 472 KB Output is correct
33 Correct 3 ms 460 KB Output is correct
34 Correct 4 ms 460 KB Output is correct
35 Correct 4 ms 460 KB Output is correct
36 Correct 3 ms 460 KB Output is correct
37 Correct 5 ms 460 KB Output is correct
38 Correct 4 ms 460 KB Output is correct
39 Correct 4 ms 460 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 3 ms 460 KB Output is correct
43 Correct 3 ms 460 KB Output is correct
44 Correct 3 ms 388 KB Output is correct
45 Correct 3 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 396 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 3 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 460 KB Output is correct
55 Correct 376 ms 12180 KB Output is correct
56 Correct 399 ms 14480 KB Output is correct
57 Correct 581 ms 14048 KB Output is correct
58 Correct 527 ms 12192 KB Output is correct
59 Correct 634 ms 12280 KB Output is correct
60 Correct 836 ms 13620 KB Output is correct
61 Correct 510 ms 12140 KB Output is correct
62 Correct 552 ms 14008 KB Output is correct
63 Correct 537 ms 10896 KB Output is correct
64 Correct 656 ms 12656 KB Output is correct
65 Correct 856 ms 13988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 320 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 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 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 320 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 1 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 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 4 ms 460 KB Output is correct
32 Correct 3 ms 472 KB Output is correct
33 Correct 3 ms 460 KB Output is correct
34 Correct 4 ms 460 KB Output is correct
35 Correct 4 ms 460 KB Output is correct
36 Correct 3 ms 460 KB Output is correct
37 Correct 5 ms 460 KB Output is correct
38 Correct 4 ms 460 KB Output is correct
39 Correct 4 ms 460 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 3 ms 460 KB Output is correct
43 Correct 3 ms 460 KB Output is correct
44 Correct 3 ms 388 KB Output is correct
45 Correct 3 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 396 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 3 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 460 KB Output is correct
55 Correct 409 ms 11732 KB Output is correct
56 Correct 489 ms 15076 KB Output is correct
57 Correct 540 ms 14052 KB Output is correct
58 Correct 505 ms 12156 KB Output is correct
59 Correct 586 ms 12176 KB Output is correct
60 Correct 602 ms 11896 KB Output is correct
61 Correct 645 ms 12240 KB Output is correct
62 Correct 801 ms 14592 KB Output is correct
63 Correct 528 ms 12732 KB Output is correct
64 Correct 629 ms 14060 KB Output is correct
65 Correct 530 ms 10396 KB Output is correct
66 Correct 619 ms 11800 KB Output is correct
67 Correct 739 ms 13272 KB Output is correct
68 Correct 797 ms 14548 KB Output is correct
69 Correct 430 ms 12852 KB Output is correct
70 Correct 457 ms 15092 KB Output is correct
71 Correct 640 ms 15128 KB Output is correct
72 Correct 513 ms 12824 KB Output is correct
73 Correct 583 ms 12736 KB Output is correct
74 Correct 748 ms 11748 KB Output is correct
75 Correct 854 ms 14560 KB Output is correct
76 Correct 539 ms 11628 KB Output is correct
77 Correct 579 ms 13692 KB Output is correct
78 Correct 700 ms 13996 KB Output is correct
79 Correct 537 ms 9568 KB Output is correct
80 Correct 675 ms 12316 KB Output is correct
81 Correct 794 ms 12384 KB Output is correct
82 Correct 897 ms 14228 KB Output is correct
83 Correct 376 ms 12180 KB Output is correct
84 Correct 399 ms 14480 KB Output is correct
85 Correct 581 ms 14048 KB Output is correct
86 Correct 527 ms 12192 KB Output is correct
87 Correct 634 ms 12280 KB Output is correct
88 Correct 836 ms 13620 KB Output is correct
89 Correct 510 ms 12140 KB Output is correct
90 Correct 552 ms 14008 KB Output is correct
91 Correct 537 ms 10896 KB Output is correct
92 Correct 656 ms 12656 KB Output is correct
93 Correct 856 ms 13988 KB Output is correct
94 Correct 430 ms 12776 KB Output is correct
95 Correct 512 ms 15076 KB Output is correct
96 Correct 537 ms 13452 KB Output is correct
97 Correct 533 ms 12936 KB Output is correct
98 Correct 561 ms 13120 KB Output is correct
99 Correct 621 ms 12024 KB Output is correct
100 Correct 769 ms 15360 KB Output is correct
101 Correct 563 ms 11196 KB Output is correct
102 Correct 581 ms 12556 KB Output is correct
103 Correct 718 ms 13956 KB Output is correct
104 Correct 595 ms 10012 KB Output is correct
105 Correct 705 ms 13180 KB Output is correct
106 Correct 851 ms 13276 KB Output is correct
107 Correct 297 ms 14912 KB Output is correct
108 Correct 413 ms 12536 KB Output is correct
109 Correct 413 ms 12488 KB Output is correct
110 Correct 416 ms 12488 KB Output is correct
111 Correct 409 ms 12472 KB Output is correct
112 Correct 405 ms 12488 KB Output is correct
113 Correct 395 ms 12488 KB Output is correct
114 Correct 406 ms 12356 KB Output is correct
115 Correct 405 ms 12344 KB Output is correct
116 Correct 405 ms 12444 KB Output is correct