답안 #678758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
678758 2023-01-06T13:29:18 Z elkernos Joker (BOI20_joker) C++17
100 / 100
485 ms 16616 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;
                }
            }
            if (last[mid] == -1) {
                last[mid] = mid;
            }
        }
        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;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 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 320 KB Output is correct
13 Correct 1 ms 340 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 324 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 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 320 KB Output is correct
13 Correct 1 ms 340 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 324 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 416 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 3 ms 464 KB Output is correct
36 Correct 2 ms 368 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 4 ms 468 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 3 ms 456 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 3 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 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 246 ms 7640 KB Output is correct
4 Correct 484 ms 12524 KB Output is correct
5 Correct 248 ms 12340 KB Output is correct
6 Correct 206 ms 7628 KB Output is correct
7 Correct 213 ms 7640 KB Output is correct
8 Correct 224 ms 5748 KB Output is correct
9 Correct 281 ms 7620 KB Output is correct
10 Correct 329 ms 8412 KB Output is correct
11 Correct 248 ms 7628 KB Output is correct
12 Correct 275 ms 8280 KB Output is correct
13 Correct 222 ms 4168 KB Output is correct
14 Correct 233 ms 5592 KB Output is correct
15 Correct 353 ms 7952 KB Output is correct
16 Correct 333 ms 8416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 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 320 KB Output is correct
13 Correct 1 ms 340 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 324 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 246 ms 7640 KB Output is correct
30 Correct 484 ms 12524 KB Output is correct
31 Correct 248 ms 12340 KB Output is correct
32 Correct 206 ms 7628 KB Output is correct
33 Correct 213 ms 7640 KB Output is correct
34 Correct 224 ms 5748 KB Output is correct
35 Correct 281 ms 7620 KB Output is correct
36 Correct 329 ms 8412 KB Output is correct
37 Correct 248 ms 7628 KB Output is correct
38 Correct 275 ms 8280 KB Output is correct
39 Correct 222 ms 4168 KB Output is correct
40 Correct 233 ms 5592 KB Output is correct
41 Correct 353 ms 7952 KB Output is correct
42 Correct 333 ms 8416 KB Output is correct
43 Correct 256 ms 11704 KB Output is correct
44 Correct 485 ms 15240 KB Output is correct
45 Correct 394 ms 15620 KB Output is correct
46 Correct 206 ms 11700 KB Output is correct
47 Correct 204 ms 11704 KB Output is correct
48 Correct 302 ms 10944 KB Output is correct
49 Correct 350 ms 12396 KB Output is correct
50 Correct 255 ms 10628 KB Output is correct
51 Correct 260 ms 11976 KB Output is correct
52 Correct 289 ms 12604 KB Output is correct
53 Correct 215 ms 8424 KB Output is correct
54 Correct 294 ms 10568 KB Output is correct
55 Correct 330 ms 11908 KB Output is correct
56 Correct 370 ms 12740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 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 320 KB Output is correct
13 Correct 1 ms 340 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 324 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 416 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 3 ms 464 KB Output is correct
36 Correct 2 ms 368 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 4 ms 468 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 3 ms 456 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 3 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 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 216 ms 9924 KB Output is correct
56 Correct 425 ms 15116 KB Output is correct
57 Correct 212 ms 14904 KB Output is correct
58 Correct 178 ms 9932 KB Output is correct
59 Correct 256 ms 9924 KB Output is correct
60 Correct 325 ms 10564 KB Output is correct
61 Correct 242 ms 9936 KB Output is correct
62 Correct 240 ms 10824 KB Output is correct
63 Correct 195 ms 7364 KB Output is correct
64 Correct 281 ms 10188 KB Output is correct
65 Correct 341 ms 10780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 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 320 KB Output is correct
13 Correct 1 ms 340 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 324 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 416 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 3 ms 464 KB Output is correct
36 Correct 2 ms 368 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 4 ms 468 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 3 ms 456 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 3 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 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 246 ms 7640 KB Output is correct
56 Correct 484 ms 12524 KB Output is correct
57 Correct 248 ms 12340 KB Output is correct
58 Correct 206 ms 7628 KB Output is correct
59 Correct 213 ms 7640 KB Output is correct
60 Correct 224 ms 5748 KB Output is correct
61 Correct 281 ms 7620 KB Output is correct
62 Correct 329 ms 8412 KB Output is correct
63 Correct 248 ms 7628 KB Output is correct
64 Correct 275 ms 8280 KB Output is correct
65 Correct 222 ms 4168 KB Output is correct
66 Correct 233 ms 5592 KB Output is correct
67 Correct 353 ms 7952 KB Output is correct
68 Correct 333 ms 8416 KB Output is correct
69 Correct 256 ms 11704 KB Output is correct
70 Correct 485 ms 15240 KB Output is correct
71 Correct 394 ms 15620 KB Output is correct
72 Correct 206 ms 11700 KB Output is correct
73 Correct 204 ms 11704 KB Output is correct
74 Correct 302 ms 10944 KB Output is correct
75 Correct 350 ms 12396 KB Output is correct
76 Correct 255 ms 10628 KB Output is correct
77 Correct 260 ms 11976 KB Output is correct
78 Correct 289 ms 12604 KB Output is correct
79 Correct 215 ms 8424 KB Output is correct
80 Correct 294 ms 10568 KB Output is correct
81 Correct 330 ms 11908 KB Output is correct
82 Correct 370 ms 12740 KB Output is correct
83 Correct 216 ms 9924 KB Output is correct
84 Correct 425 ms 15116 KB Output is correct
85 Correct 212 ms 14904 KB Output is correct
86 Correct 178 ms 9932 KB Output is correct
87 Correct 256 ms 9924 KB Output is correct
88 Correct 325 ms 10564 KB Output is correct
89 Correct 242 ms 9936 KB Output is correct
90 Correct 240 ms 10824 KB Output is correct
91 Correct 195 ms 7364 KB Output is correct
92 Correct 281 ms 10188 KB Output is correct
93 Correct 341 ms 10780 KB Output is correct
94 Correct 250 ms 12356 KB Output is correct
95 Correct 401 ms 16304 KB Output is correct
96 Correct 253 ms 15720 KB Output is correct
97 Correct 219 ms 12336 KB Output is correct
98 Correct 227 ms 12468 KB Output is correct
99 Correct 255 ms 10712 KB Output is correct
100 Correct 310 ms 13372 KB Output is correct
101 Correct 243 ms 11408 KB Output is correct
102 Correct 308 ms 12608 KB Output is correct
103 Correct 314 ms 13776 KB Output is correct
104 Correct 273 ms 9860 KB Output is correct
105 Correct 319 ms 12360 KB Output is correct
106 Correct 360 ms 13116 KB Output is correct
107 Correct 236 ms 16616 KB Output is correct
108 Correct 251 ms 12092 KB Output is correct
109 Correct 248 ms 12096 KB Output is correct
110 Correct 270 ms 12088 KB Output is correct
111 Correct 254 ms 12092 KB Output is correct
112 Correct 254 ms 12084 KB Output is correct
113 Correct 253 ms 12092 KB Output is correct
114 Correct 246 ms 12100 KB Output is correct
115 Correct 258 ms 12088 KB Output is correct
116 Correct 249 ms 12068 KB Output is correct