Submission #699271

# Submission time Handle Problem Language Result Execution time Memory
699271 2023-02-16T10:32:58 Z maomao90 Joker (BOI20_joker) C++17
100 / 100
224 ms 22416 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 200005;

int n, m, q;
int u[MAXN], v[MAXN];
vii ql[MAXN];
int mnr[MAXN];
bool ans[MAXN];

int p[MAXN], rnk[MAXN];
bool col[MAXN];
viii undostk;
void init() {
    undostk.clear();
    REP (i, 1, n + 1) {
        p[i] = i;
        rnk[i] = 1;
        col[i] = 0;
    }
}
ii findp(int u) {
    if (p[u] == u) {
        return {u, 0};
    }
    auto [tp, c] = findp(p[u]);
    return {tp, c ^ col[u]};
}
bool join(int a, int b) {
    auto [pa, ca] = findp(a);
    auto [pb, cb] = findp(b);
    if (pa == pb) {
        if (ca == cb) {
            return 0;
        }
        undostk.pb({-1, -1, -1});
        return 1;
    }
    if (rnk[pa] < rnk[pb]) {
        swap(pa, pb);
    }
    bool delta = 0;
    if (rnk[pa] == rnk[pb]) {
        delta = 1;
        rnk[pa]++;
    }
    undostk.pb({pa, pb, delta});
    p[pb] = pa;
    col[pb] = ca == cb;
    return 1;
}
void undo() {
    assert(!undostk.empty());
    auto [pa, pb, delta] = undostk.back(); undostk.pop_back();
    if (pa == -1) {
        return;
    }
    p[pb] = pb;
    col[pb] = 0;
    rnk[pa] -= delta;
}

int ti, ptr;
vii stk;
bool push(int i) {
    bool res = join(u[i], v[i]);
    if (res) {
        stk.pb({i, ++ptr});
    }
    return res;
}
void pop_front() {
    vii astk, bstk;
    while (!stk.empty()) {
        ii x = stk.back(); stk.pop_back();
        if (x.SE <= ti) {
            astk.pb(x);
        } else {
            bstk.pb(x);
        }
        if (SZ(astk) >= SZ(bstk)) {
            break;
        }
    }
    REP (i, 0, SZ(astk) + SZ(bstk)) {
        undo();
    }
    if (SZ(astk) == 0) {
        ti = bstk[0].SE;
        REP (z, 0, SZ(bstk) - 1) {
            ii i = bstk[z];
            stk.pb(i);
            join(u[i.FI], v[i.FI]);
        }
        cerr << " - " << bstk.back().FI << ' ' << bstk.back().SE << '\n';
        return;
    }
    while (!bstk.empty()) {
        ii i = bstk.back(); bstk.pop_back();
        join(u[i.FI], v[i.FI]);
        stk.pb(i);
    }
    while (SZ(astk) > 1) {
        ii i = astk.back(); astk.pop_back();
        join(u[i.FI], v[i.FI]);
        stk.pb(i);
    }
    cerr << " - " << astk.back().FI << ' ' << astk.back().SE << '\n';
}

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> n >> m >> q;
    REP (i, 1, m + 1) {
        cin >> u[i] >> v[i];
    }
    REP (i, 0, q) {
        int l, r; cin >> l >> r;
        ql[l].pb({r, i});
        /*
        while (!undostk.empty()) {
            undo();
        }
        bool pos = 1;
        REP (j, 1, l) {
            if (!join(u[j], v[j])) {
                pos = 0;
                break;
            }
        }
        if (!pos) {
            cout << "YES\n";
            continue;
        }
        REP (j, r + 1, m + 1) {
            if (!join(u[j], v[j])) {
                pos = 0;
                break;
            }
        }
        if (!pos) {
            cout << "YES\n";
            continue;
        }
        cout << "NO\n";
        */
    }
    init();
    int sr = 1;
    RREP (l, m, 1) {
        if (!join(u[l], v[l])) {
            sr = l + 1;
            break;
        }
    }
    init();
    cerr << sr << '\n';
    REP (i, sr, m + 1) {
        assert(push(i));
    }
    mnr[1] = sr - 1;
    int r = sr;
    REP (l, 2, m + 1) {
        while (r <= m + 1 && !push(l - 1)) {
            pop_front();
            r++;
        }
        cerr << ' ' << l << ' ' << r << '\n';
        mnr[l] = r - 1;
    }
    REP (l, 1, m + 1) {
        for (auto [r, i] : ql[l]) {
            ans[i] = r >= mnr[l];
        }
    }
    REP (i, 0, q) {
        if (ans[i]) {
            cout << "NO\n";
        } else {
            cout << "YES\n";
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4952 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 4 ms 4976 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 5032 KB Output is correct
11 Correct 3 ms 5036 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5024 KB Output is correct
15 Correct 3 ms 5032 KB Output is correct
16 Correct 3 ms 5084 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 3 ms 5028 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5028 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 5024 KB Output is correct
27 Correct 3 ms 5028 KB Output is correct
28 Correct 3 ms 4964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4952 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 4 ms 4976 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 5032 KB Output is correct
11 Correct 3 ms 5036 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5024 KB Output is correct
15 Correct 3 ms 5032 KB Output is correct
16 Correct 3 ms 5084 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 3 ms 5028 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5028 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 5024 KB Output is correct
27 Correct 3 ms 5028 KB Output is correct
28 Correct 3 ms 4964 KB Output is correct
29 Correct 3 ms 5192 KB Output is correct
30 Correct 4 ms 5168 KB Output is correct
31 Correct 5 ms 5204 KB Output is correct
32 Correct 4 ms 5204 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 4 ms 5204 KB Output is correct
35 Correct 5 ms 5204 KB Output is correct
36 Correct 4 ms 5204 KB Output is correct
37 Correct 5 ms 5204 KB Output is correct
38 Correct 4 ms 5296 KB Output is correct
39 Correct 4 ms 5204 KB Output is correct
40 Correct 4 ms 5204 KB Output is correct
41 Correct 4 ms 5208 KB Output is correct
42 Correct 4 ms 5164 KB Output is correct
43 Correct 4 ms 5204 KB Output is correct
44 Correct 4 ms 5204 KB Output is correct
45 Correct 4 ms 5160 KB Output is correct
46 Correct 4 ms 5204 KB Output is correct
47 Correct 4 ms 5172 KB Output is correct
48 Correct 4 ms 5204 KB Output is correct
49 Correct 4 ms 5204 KB Output is correct
50 Correct 4 ms 5136 KB Output is correct
51 Correct 5 ms 5204 KB Output is correct
52 Correct 4 ms 5172 KB Output is correct
53 Correct 5 ms 5204 KB Output is correct
54 Correct 4 ms 5204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 168 ms 15460 KB Output is correct
4 Correct 80 ms 21812 KB Output is correct
5 Correct 106 ms 17844 KB Output is correct
6 Correct 122 ms 15356 KB Output is correct
7 Correct 126 ms 15352 KB Output is correct
8 Correct 110 ms 15292 KB Output is correct
9 Correct 127 ms 15500 KB Output is correct
10 Correct 130 ms 16424 KB Output is correct
11 Correct 160 ms 15420 KB Output is correct
12 Correct 116 ms 16268 KB Output is correct
13 Correct 100 ms 14728 KB Output is correct
14 Correct 113 ms 15076 KB Output is correct
15 Correct 141 ms 15752 KB Output is correct
16 Correct 137 ms 16360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4952 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 4 ms 4976 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 5032 KB Output is correct
11 Correct 3 ms 5036 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5024 KB Output is correct
15 Correct 3 ms 5032 KB Output is correct
16 Correct 3 ms 5084 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 3 ms 5028 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5028 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 5024 KB Output is correct
27 Correct 3 ms 5028 KB Output is correct
28 Correct 3 ms 4964 KB Output is correct
29 Correct 168 ms 15460 KB Output is correct
30 Correct 80 ms 21812 KB Output is correct
31 Correct 106 ms 17844 KB Output is correct
32 Correct 122 ms 15356 KB Output is correct
33 Correct 126 ms 15352 KB Output is correct
34 Correct 110 ms 15292 KB Output is correct
35 Correct 127 ms 15500 KB Output is correct
36 Correct 130 ms 16424 KB Output is correct
37 Correct 160 ms 15420 KB Output is correct
38 Correct 116 ms 16268 KB Output is correct
39 Correct 100 ms 14728 KB Output is correct
40 Correct 113 ms 15076 KB Output is correct
41 Correct 141 ms 15752 KB Output is correct
42 Correct 137 ms 16360 KB Output is correct
43 Correct 173 ms 14324 KB Output is correct
44 Correct 84 ms 22416 KB Output is correct
45 Correct 158 ms 18568 KB Output is correct
46 Correct 118 ms 14324 KB Output is correct
47 Correct 170 ms 14348 KB Output is correct
48 Correct 142 ms 14192 KB Output is correct
49 Correct 136 ms 15256 KB Output is correct
50 Correct 165 ms 14088 KB Output is correct
51 Correct 139 ms 14656 KB Output is correct
52 Correct 145 ms 15352 KB Output is correct
53 Correct 112 ms 13620 KB Output is correct
54 Correct 150 ms 14192 KB Output is correct
55 Correct 146 ms 14736 KB Output is correct
56 Correct 136 ms 15336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4952 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 4 ms 4976 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 5032 KB Output is correct
11 Correct 3 ms 5036 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5024 KB Output is correct
15 Correct 3 ms 5032 KB Output is correct
16 Correct 3 ms 5084 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 3 ms 5028 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5028 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 5024 KB Output is correct
27 Correct 3 ms 5028 KB Output is correct
28 Correct 3 ms 4964 KB Output is correct
29 Correct 3 ms 5192 KB Output is correct
30 Correct 4 ms 5168 KB Output is correct
31 Correct 5 ms 5204 KB Output is correct
32 Correct 4 ms 5204 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 4 ms 5204 KB Output is correct
35 Correct 5 ms 5204 KB Output is correct
36 Correct 4 ms 5204 KB Output is correct
37 Correct 5 ms 5204 KB Output is correct
38 Correct 4 ms 5296 KB Output is correct
39 Correct 4 ms 5204 KB Output is correct
40 Correct 4 ms 5204 KB Output is correct
41 Correct 4 ms 5208 KB Output is correct
42 Correct 4 ms 5164 KB Output is correct
43 Correct 4 ms 5204 KB Output is correct
44 Correct 4 ms 5204 KB Output is correct
45 Correct 4 ms 5160 KB Output is correct
46 Correct 4 ms 5204 KB Output is correct
47 Correct 4 ms 5172 KB Output is correct
48 Correct 4 ms 5204 KB Output is correct
49 Correct 4 ms 5204 KB Output is correct
50 Correct 4 ms 5136 KB Output is correct
51 Correct 5 ms 5204 KB Output is correct
52 Correct 4 ms 5172 KB Output is correct
53 Correct 5 ms 5204 KB Output is correct
54 Correct 4 ms 5204 KB Output is correct
55 Correct 143 ms 12212 KB Output is correct
56 Correct 61 ms 19612 KB Output is correct
57 Correct 67 ms 16328 KB Output is correct
58 Correct 93 ms 12184 KB Output is correct
59 Correct 104 ms 12204 KB Output is correct
60 Correct 121 ms 12852 KB Output is correct
61 Correct 125 ms 12224 KB Output is correct
62 Correct 95 ms 13224 KB Output is correct
63 Correct 76 ms 11624 KB Output is correct
64 Correct 113 ms 12292 KB Output is correct
65 Correct 127 ms 12852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4952 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 4 ms 4976 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 5032 KB Output is correct
11 Correct 3 ms 5036 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5024 KB Output is correct
15 Correct 3 ms 5032 KB Output is correct
16 Correct 3 ms 5084 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 3 ms 5028 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5028 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 5024 KB Output is correct
27 Correct 3 ms 5028 KB Output is correct
28 Correct 3 ms 4964 KB Output is correct
29 Correct 3 ms 5192 KB Output is correct
30 Correct 4 ms 5168 KB Output is correct
31 Correct 5 ms 5204 KB Output is correct
32 Correct 4 ms 5204 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 4 ms 5204 KB Output is correct
35 Correct 5 ms 5204 KB Output is correct
36 Correct 4 ms 5204 KB Output is correct
37 Correct 5 ms 5204 KB Output is correct
38 Correct 4 ms 5296 KB Output is correct
39 Correct 4 ms 5204 KB Output is correct
40 Correct 4 ms 5204 KB Output is correct
41 Correct 4 ms 5208 KB Output is correct
42 Correct 4 ms 5164 KB Output is correct
43 Correct 4 ms 5204 KB Output is correct
44 Correct 4 ms 5204 KB Output is correct
45 Correct 4 ms 5160 KB Output is correct
46 Correct 4 ms 5204 KB Output is correct
47 Correct 4 ms 5172 KB Output is correct
48 Correct 4 ms 5204 KB Output is correct
49 Correct 4 ms 5204 KB Output is correct
50 Correct 4 ms 5136 KB Output is correct
51 Correct 5 ms 5204 KB Output is correct
52 Correct 4 ms 5172 KB Output is correct
53 Correct 5 ms 5204 KB Output is correct
54 Correct 4 ms 5204 KB Output is correct
55 Correct 168 ms 15460 KB Output is correct
56 Correct 80 ms 21812 KB Output is correct
57 Correct 106 ms 17844 KB Output is correct
58 Correct 122 ms 15356 KB Output is correct
59 Correct 126 ms 15352 KB Output is correct
60 Correct 110 ms 15292 KB Output is correct
61 Correct 127 ms 15500 KB Output is correct
62 Correct 130 ms 16424 KB Output is correct
63 Correct 160 ms 15420 KB Output is correct
64 Correct 116 ms 16268 KB Output is correct
65 Correct 100 ms 14728 KB Output is correct
66 Correct 113 ms 15076 KB Output is correct
67 Correct 141 ms 15752 KB Output is correct
68 Correct 137 ms 16360 KB Output is correct
69 Correct 173 ms 14324 KB Output is correct
70 Correct 84 ms 22416 KB Output is correct
71 Correct 158 ms 18568 KB Output is correct
72 Correct 118 ms 14324 KB Output is correct
73 Correct 170 ms 14348 KB Output is correct
74 Correct 142 ms 14192 KB Output is correct
75 Correct 136 ms 15256 KB Output is correct
76 Correct 165 ms 14088 KB Output is correct
77 Correct 139 ms 14656 KB Output is correct
78 Correct 145 ms 15352 KB Output is correct
79 Correct 112 ms 13620 KB Output is correct
80 Correct 150 ms 14192 KB Output is correct
81 Correct 146 ms 14736 KB Output is correct
82 Correct 136 ms 15336 KB Output is correct
83 Correct 143 ms 12212 KB Output is correct
84 Correct 61 ms 19612 KB Output is correct
85 Correct 67 ms 16328 KB Output is correct
86 Correct 93 ms 12184 KB Output is correct
87 Correct 104 ms 12204 KB Output is correct
88 Correct 121 ms 12852 KB Output is correct
89 Correct 125 ms 12224 KB Output is correct
90 Correct 95 ms 13224 KB Output is correct
91 Correct 76 ms 11624 KB Output is correct
92 Correct 113 ms 12292 KB Output is correct
93 Correct 127 ms 12852 KB Output is correct
94 Correct 212 ms 16396 KB Output is correct
95 Correct 197 ms 20924 KB Output is correct
96 Correct 128 ms 20616 KB Output is correct
97 Correct 143 ms 16408 KB Output is correct
98 Correct 166 ms 16476 KB Output is correct
99 Correct 142 ms 15920 KB Output is correct
100 Correct 149 ms 17320 KB Output is correct
101 Correct 224 ms 16352 KB Output is correct
102 Correct 175 ms 16768 KB Output is correct
103 Correct 176 ms 17676 KB Output is correct
104 Correct 165 ms 15924 KB Output is correct
105 Correct 163 ms 16484 KB Output is correct
106 Correct 212 ms 17144 KB Output is correct
107 Correct 101 ms 18116 KB Output is correct
108 Correct 195 ms 15684 KB Output is correct
109 Correct 194 ms 15784 KB Output is correct
110 Correct 198 ms 15908 KB Output is correct
111 Correct 192 ms 15780 KB Output is correct
112 Correct 211 ms 15808 KB Output is correct
113 Correct 199 ms 15824 KB Output is correct
114 Correct 197 ms 15796 KB Output is correct
115 Correct 200 ms 15812 KB Output is correct
116 Correct 198 ms 15664 KB Output is correct