Submission #678912

# Submission time Handle Problem Language Result Execution time Memory
678912 2023-01-06T22:18:21 Z elkernos Joker (BOI20_joker) C++17
100 / 100
401 ms 14736 KB
// while (clock()<=69*CLOCKS_PER_SEC)
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("O3")
// #pragma GCC target ("avx2")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                    \
    sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
    {
sim > struct rge {
    c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef XOX
    ~debug()
    {
        cerr << endl;
    }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
    ris << "" << d.first << " --> " << d.second << "";
}
sim dor(rge<c> d)
{
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c &)
    {
        ris;
    }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
#ifdef XOX
#warning Times may differ!!!
#endif
 
#define endl '\n'
#define pb emplace_back
#define vt vector
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const int nax = 1000 * 1007, mod = 1e9 + 7;
 
struct RollbackUF {
    vt<int> e;
    vt<pii> st;
    RollbackUF(int n) : e(n, -1) {}
    int size(int x) { return -e[find(x)]; }
    int find(int x) { return e[x] < 0 ? x : find(e[x]); }
    int time() { return sz(st); }
    void rollback(int t)
    {
        for (int i = time(); i-- > t;)
            e[st[i].first] = st[i].second;
        st.resize(t);
    }
    bool join(int a, int b)
    {
        a = find(a), b = find(b);
        if (a == b) return false;
        if (e[a] > e[b]) swap(a, b);
        st.pb(a, e[a]);
        st.pb(b, e[b]);
        e[a] += e[b];
        e[b] = a;
        return true;
    }
};
 
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n, m, q;
    cin >> n >> m >> q;
    vt<pii> edges(m);
    for (auto &[a, b] : edges) {
        cin >> a >> b;
    }
    RollbackUF uf(2 * n + 12);
    vt<int> last(m, -1);
    auto lacz = [&](int i) {
        if (i == m) {
            return;
        }
        uf.join(edges[i].first, edges[i].second + n);
        uf.join(edges[i].first + n, edges[i].second);
    };
    auto same = [&](int i) {
        if (i == m) {
            return false;
        }
        return uf.find(edges[i].first) == uf.find(edges[i].first + n);
    };
    function<void(int, int, int, int)> rek = [&](int l, int r, int a, int b) {
        int mid = (l + r) / 2;
        int t = uf.time();
        debug() << imie(l) imie(mid) imie(r) imie(a) imie(b);
        for (int i = l; i < mid; i++) {
            lacz(i);
            if (same(i)) {
                last[mid] = m;
                break;
            }
        }
        if (last[mid] == -1) {
            for (int i = b; i >= mid; i--) {
                lacz(i);
                if (same(i)) {
                    last[mid] = i;
                    break;
                }
            }
        }
        uf.rollback(t);
        {
            int flag = 0;
            for (int i = b; i > last[mid]; i--) {
                lacz(i);
                if (same(i)) {
                    flag = 1;
                    break;
                }
            }
            if (flag) {
                debug() << imie(l) imie(mid - 1) imie(last[mid]);
                for (int i = l; i < mid; i++) {
                    last[i] = last[mid];
                }
            }
            else if (l < mid) {
                rek(l, mid - 1, a, last[mid]);
            }
            uf.rollback(t);
        }
        {
            int flag = 0;
            for (int i = l; i <= mid; i++) {
                lacz(i);
                if (same(i)) {
                    flag = 1;
                    break;
                }
            }
            if (flag) {
                debug() << imie(mid + 1) imie(r) imie(last[mid]);
                for (int i = mid + 1; i <= r; i++) {
                    last[i] = m;
                }
            }
            else if (mid < r) {
                rek(mid + 1, r, last[mid], b);
            }
            uf.rollback(t);
        }
    };
    rek(0, m - 1, 0, m);
    debug() << imie(last);
    while (q--) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        cout << (last[a] <= b ? "NO" : "YES") << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 500 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 4 ms 460 KB Output is correct
38 Correct 3 ms 464 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 3 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 328 KB Output is correct
44 Correct 2 ms 368 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 3 ms 468 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 2 ms 460 KB Output is correct
54 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 245 ms 7672 KB Output is correct
4 Correct 270 ms 14028 KB Output is correct
5 Correct 265 ms 13892 KB Output is correct
6 Correct 200 ms 9408 KB Output is correct
7 Correct 229 ms 9356 KB Output is correct
8 Correct 232 ms 8020 KB Output is correct
9 Correct 268 ms 9220 KB Output is correct
10 Correct 324 ms 10560 KB Output is correct
11 Correct 266 ms 8952 KB Output is correct
12 Correct 277 ms 10212 KB Output is correct
13 Correct 215 ms 6244 KB Output is correct
14 Correct 240 ms 7888 KB Output is correct
15 Correct 337 ms 9568 KB Output is correct
16 Correct 340 ms 10340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 245 ms 7672 KB Output is correct
30 Correct 270 ms 14028 KB Output is correct
31 Correct 265 ms 13892 KB Output is correct
32 Correct 200 ms 9408 KB Output is correct
33 Correct 229 ms 9356 KB Output is correct
34 Correct 232 ms 8020 KB Output is correct
35 Correct 268 ms 9220 KB Output is correct
36 Correct 324 ms 10560 KB Output is correct
37 Correct 266 ms 8952 KB Output is correct
38 Correct 277 ms 10212 KB Output is correct
39 Correct 215 ms 6244 KB Output is correct
40 Correct 240 ms 7888 KB Output is correct
41 Correct 337 ms 9568 KB Output is correct
42 Correct 340 ms 10340 KB Output is correct
43 Correct 249 ms 9408 KB Output is correct
44 Correct 269 ms 13992 KB Output is correct
45 Correct 401 ms 13840 KB Output is correct
46 Correct 213 ms 9404 KB Output is correct
47 Correct 229 ms 9428 KB Output is correct
48 Correct 291 ms 9028 KB Output is correct
49 Correct 353 ms 10548 KB Output is correct
50 Correct 246 ms 8628 KB Output is correct
51 Correct 279 ms 9628 KB Output is correct
52 Correct 280 ms 10432 KB Output is correct
53 Correct 229 ms 6252 KB Output is correct
54 Correct 282 ms 8796 KB Output is correct
55 Correct 348 ms 9636 KB Output is correct
56 Correct 343 ms 10388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 500 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 4 ms 460 KB Output is correct
38 Correct 3 ms 464 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 3 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 328 KB Output is correct
44 Correct 2 ms 368 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 3 ms 468 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 2 ms 460 KB Output is correct
54 Correct 3 ms 468 KB Output is correct
55 Correct 217 ms 9800 KB Output is correct
56 Correct 234 ms 14736 KB Output is correct
57 Correct 214 ms 14524 KB Output is correct
58 Correct 162 ms 9800 KB Output is correct
59 Correct 262 ms 9708 KB Output is correct
60 Correct 334 ms 10184 KB Output is correct
61 Correct 239 ms 9720 KB Output is correct
62 Correct 251 ms 10400 KB Output is correct
63 Correct 196 ms 7252 KB Output is correct
64 Correct 276 ms 9916 KB Output is correct
65 Correct 311 ms 10436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 500 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 4 ms 460 KB Output is correct
38 Correct 3 ms 464 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 3 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 328 KB Output is correct
44 Correct 2 ms 368 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 3 ms 468 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 2 ms 460 KB Output is correct
54 Correct 3 ms 468 KB Output is correct
55 Correct 245 ms 7672 KB Output is correct
56 Correct 270 ms 14028 KB Output is correct
57 Correct 265 ms 13892 KB Output is correct
58 Correct 200 ms 9408 KB Output is correct
59 Correct 229 ms 9356 KB Output is correct
60 Correct 232 ms 8020 KB Output is correct
61 Correct 268 ms 9220 KB Output is correct
62 Correct 324 ms 10560 KB Output is correct
63 Correct 266 ms 8952 KB Output is correct
64 Correct 277 ms 10212 KB Output is correct
65 Correct 215 ms 6244 KB Output is correct
66 Correct 240 ms 7888 KB Output is correct
67 Correct 337 ms 9568 KB Output is correct
68 Correct 340 ms 10340 KB Output is correct
69 Correct 249 ms 9408 KB Output is correct
70 Correct 269 ms 13992 KB Output is correct
71 Correct 401 ms 13840 KB Output is correct
72 Correct 213 ms 9404 KB Output is correct
73 Correct 229 ms 9428 KB Output is correct
74 Correct 291 ms 9028 KB Output is correct
75 Correct 353 ms 10548 KB Output is correct
76 Correct 246 ms 8628 KB Output is correct
77 Correct 279 ms 9628 KB Output is correct
78 Correct 280 ms 10432 KB Output is correct
79 Correct 229 ms 6252 KB Output is correct
80 Correct 282 ms 8796 KB Output is correct
81 Correct 348 ms 9636 KB Output is correct
82 Correct 343 ms 10388 KB Output is correct
83 Correct 217 ms 9800 KB Output is correct
84 Correct 234 ms 14736 KB Output is correct
85 Correct 214 ms 14524 KB Output is correct
86 Correct 162 ms 9800 KB Output is correct
87 Correct 262 ms 9708 KB Output is correct
88 Correct 334 ms 10184 KB Output is correct
89 Correct 239 ms 9720 KB Output is correct
90 Correct 251 ms 10400 KB Output is correct
91 Correct 196 ms 7252 KB Output is correct
92 Correct 276 ms 9916 KB Output is correct
93 Correct 311 ms 10436 KB Output is correct
94 Correct 259 ms 9520 KB Output is correct
95 Correct 384 ms 13632 KB Output is correct
96 Correct 252 ms 13248 KB Output is correct
97 Correct 207 ms 9616 KB Output is correct
98 Correct 221 ms 9536 KB Output is correct
99 Correct 256 ms 7992 KB Output is correct
100 Correct 293 ms 10428 KB Output is correct
101 Correct 242 ms 8620 KB Output is correct
102 Correct 286 ms 9644 KB Output is correct
103 Correct 321 ms 10684 KB Output is correct
104 Correct 241 ms 7124 KB Output is correct
105 Correct 317 ms 9400 KB Output is correct
106 Correct 354 ms 10032 KB Output is correct
107 Correct 245 ms 13636 KB Output is correct
108 Correct 256 ms 9268 KB Output is correct
109 Correct 248 ms 9260 KB Output is correct
110 Correct 245 ms 9448 KB Output is correct
111 Correct 246 ms 9272 KB Output is correct
112 Correct 254 ms 9328 KB Output is correct
113 Correct 245 ms 9544 KB Output is correct
114 Correct 245 ms 9544 KB Output is correct
115 Correct 253 ms 9188 KB Output is correct
116 Correct 251 ms 9332 KB Output is correct