답안 #993861

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
993861 2024-06-06T15:27:19 Z Fatonim Joker (BOI20_joker) C++17
100 / 100
171 ms 17348 KB
// "We create our own demons."
#include <bits/stdc++.h>

using namespace std;

#ifdef ONPC
    #include "debug.h"
#else
    #define dbg(...)
#endif

#define int long long
#define ll long long
#define ld long double
#define pi pair<int, int>
// vector
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define maxel(x) (*max_element(all(x)))
#define minel(x) (*min_element(all(x)))
#define maxpos(x) (max_element(all(x)) - x.begin())
#define minpos(x) (min_element(all(x)) - x.begin())
#define srt(x) (sort(all(x)))
#define rev(x) (reverse(all(x)))
// bitwise operations
#define cnt_bit(n) __builtin_popcountll(n)
#define low_bit(n) ((n) & (-(n)))
#define bit(n, i) (((n) >> (i)) & 1)
#define set_bit(n, i) ((n) | (1LL << (i)))
#define reset_bit(n, i) ((n) & ~(1LL << (i)))
#define flip_bit(n, i) ((n) ^ (1LL << (i)))
// math
#define sqr(n) ((n) * (n))
#define divup(a, b) (((a) + (b)-1) / (b))
// ostream
#define Fixed(a) cout << fixed << setprecision(12) << a;

template <class T> void chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template <class T> void chmax(T& a, const T& b) { return b > a ? a = b, 1 : 0; }

template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> using max_queue = priority_queue<T, vector<T>, less<T>>;

template <class T> using V = vector<T>;
using vi = V<int>;
using vd = V<ld>;
using vb = V<bool>;
using vpi = V<pi>;
using vvi = V<vi>;
using vvb = V<vb>;

const int mod = 1e9 + 7; // 998244353 1e9 + 7
const ll inf = (int)(1e18) + 7;
const int inf_s = 1e9 + 7;
const ld eps = 1e-9;

const int B = 32;
const int N = 1000 + 3;
const int logn = 20;
const int maxn = 2e5 + 7;
/////////////////////////solve/////////////////////////

int n, m, q;
pi e[maxn];
int lst[maxn];

int p[maxn], sz[maxn], len[maxn];
vi hist;

pi get(int a) {
    if (a != p[a]) {
        pi cur = get(p[a]);
        return {cur.first, cur.second ^ len[a]};
    }
    return {a, 0};
}

bool unite(int i) {
    if (i == m) return 0;
    auto [a, x] = get(e[i].first);
    auto [b, y] = get(e[i].second);
    if (a == b) {
        return x ^ y ^ 1;
    }
    if (sz[a] > sz[b]) swap(a, b);
    sz[b] += sz[a];
    p[a] = b;
    len[a] = x ^ y ^ 1;
    hist.push_back(a);
    return 0;
}

void rb(int k) {
    while (sz(hist) > k) {
        int a = hist.back();
        hist.pop_back();
        sz[p[a]] -= sz[a];
        p[a] = a;
        len[a] = 0;
    }
}

void divi(int l, int r, int tl, int tr) {
    if (l > r) return;
    int mid = (l + r) / 2;
    bool ok = 0;
    int k = sz(hist);
    for (int i = l; i < mid; ++i) {
        ok |= unite(i);
    }
    if (ok) {
        lst[mid] = m;
        dbg("d");
    }
    else {
        for (int i = tr; i >= tl; --i) {
            ok |= unite(i);
            if (ok) {
                lst[mid] = i;
                break;
            }
        }
    }
    dbg(l, r, tl, tr, mid, lst[mid]);
    rb(k);
    ok = 0;
    for (int i = l; i <= mid; ++i)
        ok |= unite(i);
    if (ok) {
        for (int i = mid + 1; i <= r; ++i) {
            lst[i] = m;
        }
    }
    else divi(mid + 1, r, lst[mid], tr);
    rb(k);
    ok = 0;
    for (int i = lst[mid] + 1; i <= tr; ++i)
        ok |= unite(i);
    divi(l, mid - 1, tl, lst[mid]);
    rb(k);
}

void solve() {
    cin >> n >> m >> q;

    for (int i = 0; i < n; ++i) {
        sz[i] = 1;
        p[i] = i;
        len[i] = 0;
    }
    
    for (int i = 0; i < m; ++i) {
        int v, u;
        cin >> v >> u;
        --v; --u;

        e[i] = {v, u};
    }

    divi(0, m - 1, 0, m);
    for (int i = 0; i < m; ++i) {
        dbg(lst[i], i);
    }

    while (q--) {
        int l, r;
        cin >> l >> r;
        --l; --r;

        cout << (r < lst[l] ? "YES" : "NO") << "\n";
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
#ifdef ONPC
        cerr << "===========" << i << "===========" << '\n';
#endif
        solve();
    }

#ifdef ONPC
    cerr << endl << "Time " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 412 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 456 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 412 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 456 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 620 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 540 KB Output is correct
37 Correct 1 ms 652 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 2 ms 608 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 476 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 532 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 109 ms 13048 KB Output is correct
4 Correct 137 ms 14276 KB Output is correct
5 Correct 106 ms 15552 KB Output is correct
6 Correct 96 ms 13064 KB Output is correct
7 Correct 98 ms 13004 KB Output is correct
8 Correct 121 ms 11216 KB Output is correct
9 Correct 131 ms 12364 KB Output is correct
10 Correct 160 ms 15288 KB Output is correct
11 Correct 117 ms 12736 KB Output is correct
12 Correct 130 ms 15260 KB Output is correct
13 Correct 115 ms 10200 KB Output is correct
14 Correct 121 ms 11760 KB Output is correct
15 Correct 164 ms 14160 KB Output is correct
16 Correct 164 ms 15812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 412 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 456 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 109 ms 13048 KB Output is correct
30 Correct 137 ms 14276 KB Output is correct
31 Correct 106 ms 15552 KB Output is correct
32 Correct 96 ms 13064 KB Output is correct
33 Correct 98 ms 13004 KB Output is correct
34 Correct 121 ms 11216 KB Output is correct
35 Correct 131 ms 12364 KB Output is correct
36 Correct 160 ms 15288 KB Output is correct
37 Correct 117 ms 12736 KB Output is correct
38 Correct 130 ms 15260 KB Output is correct
39 Correct 115 ms 10200 KB Output is correct
40 Correct 121 ms 11760 KB Output is correct
41 Correct 164 ms 14160 KB Output is correct
42 Correct 164 ms 15812 KB Output is correct
43 Correct 124 ms 13256 KB Output is correct
44 Correct 136 ms 14540 KB Output is correct
45 Correct 161 ms 16464 KB Output is correct
46 Correct 97 ms 13268 KB Output is correct
47 Correct 98 ms 13352 KB Output is correct
48 Correct 150 ms 12936 KB Output is correct
49 Correct 167 ms 15892 KB Output is correct
50 Correct 118 ms 12492 KB Output is correct
51 Correct 126 ms 14508 KB Output is correct
52 Correct 134 ms 16076 KB Output is correct
53 Correct 120 ms 10708 KB Output is correct
54 Correct 143 ms 12696 KB Output is correct
55 Correct 158 ms 14540 KB Output is correct
56 Correct 165 ms 15968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 412 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 456 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 620 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 540 KB Output is correct
37 Correct 1 ms 652 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 2 ms 608 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 476 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 532 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 616 KB Output is correct
55 Correct 81 ms 10704 KB Output is correct
56 Correct 111 ms 13008 KB Output is correct
57 Correct 80 ms 13256 KB Output is correct
58 Correct 78 ms 10704 KB Output is correct
59 Correct 115 ms 10704 KB Output is correct
60 Correct 141 ms 12492 KB Output is correct
61 Correct 104 ms 10672 KB Output is correct
62 Correct 110 ms 12996 KB Output is correct
63 Correct 91 ms 8656 KB Output is correct
64 Correct 125 ms 11208 KB Output is correct
65 Correct 142 ms 12996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 412 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 456 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 620 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 540 KB Output is correct
37 Correct 1 ms 652 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 2 ms 608 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 476 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 532 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 616 KB Output is correct
55 Correct 109 ms 13048 KB Output is correct
56 Correct 137 ms 14276 KB Output is correct
57 Correct 106 ms 15552 KB Output is correct
58 Correct 96 ms 13064 KB Output is correct
59 Correct 98 ms 13004 KB Output is correct
60 Correct 121 ms 11216 KB Output is correct
61 Correct 131 ms 12364 KB Output is correct
62 Correct 160 ms 15288 KB Output is correct
63 Correct 117 ms 12736 KB Output is correct
64 Correct 130 ms 15260 KB Output is correct
65 Correct 115 ms 10200 KB Output is correct
66 Correct 121 ms 11760 KB Output is correct
67 Correct 164 ms 14160 KB Output is correct
68 Correct 164 ms 15812 KB Output is correct
69 Correct 124 ms 13256 KB Output is correct
70 Correct 136 ms 14540 KB Output is correct
71 Correct 161 ms 16464 KB Output is correct
72 Correct 97 ms 13268 KB Output is correct
73 Correct 98 ms 13352 KB Output is correct
74 Correct 150 ms 12936 KB Output is correct
75 Correct 167 ms 15892 KB Output is correct
76 Correct 118 ms 12492 KB Output is correct
77 Correct 126 ms 14508 KB Output is correct
78 Correct 134 ms 16076 KB Output is correct
79 Correct 120 ms 10708 KB Output is correct
80 Correct 143 ms 12696 KB Output is correct
81 Correct 158 ms 14540 KB Output is correct
82 Correct 165 ms 15968 KB Output is correct
83 Correct 81 ms 10704 KB Output is correct
84 Correct 111 ms 13008 KB Output is correct
85 Correct 80 ms 13256 KB Output is correct
86 Correct 78 ms 10704 KB Output is correct
87 Correct 115 ms 10704 KB Output is correct
88 Correct 141 ms 12492 KB Output is correct
89 Correct 104 ms 10672 KB Output is correct
90 Correct 110 ms 12996 KB Output is correct
91 Correct 91 ms 8656 KB Output is correct
92 Correct 125 ms 11208 KB Output is correct
93 Correct 142 ms 12996 KB Output is correct
94 Correct 110 ms 14024 KB Output is correct
95 Correct 150 ms 17148 KB Output is correct
96 Correct 115 ms 16632 KB Output is correct
97 Correct 105 ms 14044 KB Output is correct
98 Correct 105 ms 14028 KB Output is correct
99 Correct 137 ms 12752 KB Output is correct
100 Correct 146 ms 16840 KB Output is correct
101 Correct 122 ms 13256 KB Output is correct
102 Correct 136 ms 15256 KB Output is correct
103 Correct 156 ms 16844 KB Output is correct
104 Correct 131 ms 12096 KB Output is correct
105 Correct 159 ms 14440 KB Output is correct
106 Correct 171 ms 16400 KB Output is correct
107 Correct 85 ms 17348 KB Output is correct
108 Correct 106 ms 13724 KB Output is correct
109 Correct 106 ms 13768 KB Output is correct
110 Correct 122 ms 13704 KB Output is correct
111 Correct 106 ms 13772 KB Output is correct
112 Correct 104 ms 13768 KB Output is correct
113 Correct 108 ms 13772 KB Output is correct
114 Correct 111 ms 13644 KB Output is correct
115 Correct 105 ms 13776 KB Output is correct
116 Correct 111 ms 13752 KB Output is correct