Submission #992460

# Submission time Handle Problem Language Result Execution time Memory
992460 2024-06-04T13:37:14 Z Fatonim Joker (BOI20_joker) C++17
39 / 100
2000 ms 12636 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/////////////////////////

pi e[maxn];

struct DSU {
    vi p, sz, len;
    DSU(int n) {
        p.resize(n), sz.resize(n, 1);
        len.resize(n, 0);
        for (int i = 0; i < n; ++i) {
            p[i] = i;
        }
    }
    pi get(int a) {
        if (a != p[a]) {
            pi res = get(p[a]);
            p[a] = res.first;
            len[a] ^= res.second;
        }
        return {p[a], len[a]};
    }
    bool unite(int aa, int bb) {
        auto [a, x] = get(aa);
        auto [b, y] = get(bb);
        if (a == b) return x == y;
        if (sz[a] > sz[b]) swap(a, b);
        sz[b] += sz[a];
        p[a] = b;
        len[a] = x ^ y ^ 1;
        return 0;
    }
};

int ans[maxn];

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

    for (int i = 0; i < m; ++i) {
        int v, u;
        cin >> v >> u;
        --v; --u;

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

    ans[m] = 0;
    DSU dsu(n);
    for (int i = m - 1; i >= 0; --i) {
        auto [v, u] = e[i];
        ans[i] = ans[i + 1] | dsu.unite(v, u);
    }

    for (int qi = 0; qi < q; ++qi) {
        int l, r;
        cin >> l >> r;
        --l, --r;

        if (l != 0) {
            bool ok = 0;
            DSU dsu(n);
            for (int i = 0; i < l; ++i) {
                auto [v, u] = e[i];
                dbg(v, u);
                if (dsu.unite(v, u)) ok = 1;
            }
            for (int i = r + 1; i < m; ++i) {
                auto [v, u] = e[i];
                dbg(v, u);
                if (dsu.unite(v, u)) ok = 1;
            }

            cout << (ok ? "YES" : "NO") << "\n";
            continue;
        }

        cout << (ans[r + 1] ? "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
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 20 ms 2392 KB Output is correct
30 Correct 29 ms 2396 KB Output is correct
31 Correct 26 ms 2616 KB Output is correct
32 Correct 22 ms 2392 KB Output is correct
33 Correct 17 ms 2564 KB Output is correct
34 Correct 34 ms 2392 KB Output is correct
35 Correct 31 ms 2396 KB Output is correct
36 Correct 18 ms 2396 KB Output is correct
37 Correct 30 ms 2396 KB Output is correct
38 Correct 33 ms 2396 KB Output is correct
39 Correct 21 ms 2396 KB Output is correct
40 Correct 20 ms 2396 KB Output is correct
41 Correct 28 ms 2396 KB Output is correct
42 Correct 19 ms 2392 KB Output is correct
43 Correct 35 ms 2396 KB Output is correct
44 Correct 29 ms 2392 KB Output is correct
45 Correct 33 ms 2392 KB Output is correct
46 Correct 36 ms 2392 KB Output is correct
47 Correct 19 ms 2396 KB Output is correct
48 Correct 22 ms 2396 KB Output is correct
49 Correct 31 ms 2596 KB Output is correct
50 Correct 28 ms 2396 KB Output is correct
51 Correct 25 ms 2392 KB Output is correct
52 Correct 20 ms 2392 KB Output is correct
53 Correct 25 ms 2592 KB Output is correct
54 Correct 30 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 46 ms 8016 KB Output is correct
4 Correct 58 ms 10324 KB Output is correct
5 Correct 65 ms 9812 KB Output is correct
6 Correct 50 ms 8016 KB Output is correct
7 Correct 47 ms 8020 KB Output is correct
8 Correct 42 ms 7248 KB Output is correct
9 Correct 66 ms 8272 KB Output is correct
10 Correct 51 ms 10560 KB Output is correct
11 Correct 63 ms 7892 KB Output is correct
12 Correct 52 ms 9808 KB Output is correct
13 Correct 46 ms 6168 KB Output is correct
14 Correct 46 ms 7004 KB Output is correct
15 Correct 52 ms 8972 KB Output is correct
16 Correct 51 ms 10324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 46 ms 8016 KB Output is correct
30 Correct 58 ms 10324 KB Output is correct
31 Correct 65 ms 9812 KB Output is correct
32 Correct 50 ms 8016 KB Output is correct
33 Correct 47 ms 8020 KB Output is correct
34 Correct 42 ms 7248 KB Output is correct
35 Correct 66 ms 8272 KB Output is correct
36 Correct 51 ms 10560 KB Output is correct
37 Correct 63 ms 7892 KB Output is correct
38 Correct 52 ms 9808 KB Output is correct
39 Correct 46 ms 6168 KB Output is correct
40 Correct 46 ms 7004 KB Output is correct
41 Correct 52 ms 8972 KB Output is correct
42 Correct 51 ms 10324 KB Output is correct
43 Execution timed out 2079 ms 12636 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 20 ms 2392 KB Output is correct
30 Correct 29 ms 2396 KB Output is correct
31 Correct 26 ms 2616 KB Output is correct
32 Correct 22 ms 2392 KB Output is correct
33 Correct 17 ms 2564 KB Output is correct
34 Correct 34 ms 2392 KB Output is correct
35 Correct 31 ms 2396 KB Output is correct
36 Correct 18 ms 2396 KB Output is correct
37 Correct 30 ms 2396 KB Output is correct
38 Correct 33 ms 2396 KB Output is correct
39 Correct 21 ms 2396 KB Output is correct
40 Correct 20 ms 2396 KB Output is correct
41 Correct 28 ms 2396 KB Output is correct
42 Correct 19 ms 2392 KB Output is correct
43 Correct 35 ms 2396 KB Output is correct
44 Correct 29 ms 2392 KB Output is correct
45 Correct 33 ms 2392 KB Output is correct
46 Correct 36 ms 2392 KB Output is correct
47 Correct 19 ms 2396 KB Output is correct
48 Correct 22 ms 2396 KB Output is correct
49 Correct 31 ms 2596 KB Output is correct
50 Correct 28 ms 2396 KB Output is correct
51 Correct 25 ms 2392 KB Output is correct
52 Correct 20 ms 2392 KB Output is correct
53 Correct 25 ms 2592 KB Output is correct
54 Correct 30 ms 2396 KB Output is correct
55 Execution timed out 2053 ms 9896 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 20 ms 2392 KB Output is correct
30 Correct 29 ms 2396 KB Output is correct
31 Correct 26 ms 2616 KB Output is correct
32 Correct 22 ms 2392 KB Output is correct
33 Correct 17 ms 2564 KB Output is correct
34 Correct 34 ms 2392 KB Output is correct
35 Correct 31 ms 2396 KB Output is correct
36 Correct 18 ms 2396 KB Output is correct
37 Correct 30 ms 2396 KB Output is correct
38 Correct 33 ms 2396 KB Output is correct
39 Correct 21 ms 2396 KB Output is correct
40 Correct 20 ms 2396 KB Output is correct
41 Correct 28 ms 2396 KB Output is correct
42 Correct 19 ms 2392 KB Output is correct
43 Correct 35 ms 2396 KB Output is correct
44 Correct 29 ms 2392 KB Output is correct
45 Correct 33 ms 2392 KB Output is correct
46 Correct 36 ms 2392 KB Output is correct
47 Correct 19 ms 2396 KB Output is correct
48 Correct 22 ms 2396 KB Output is correct
49 Correct 31 ms 2596 KB Output is correct
50 Correct 28 ms 2396 KB Output is correct
51 Correct 25 ms 2392 KB Output is correct
52 Correct 20 ms 2392 KB Output is correct
53 Correct 25 ms 2592 KB Output is correct
54 Correct 30 ms 2396 KB Output is correct
55 Correct 46 ms 8016 KB Output is correct
56 Correct 58 ms 10324 KB Output is correct
57 Correct 65 ms 9812 KB Output is correct
58 Correct 50 ms 8016 KB Output is correct
59 Correct 47 ms 8020 KB Output is correct
60 Correct 42 ms 7248 KB Output is correct
61 Correct 66 ms 8272 KB Output is correct
62 Correct 51 ms 10560 KB Output is correct
63 Correct 63 ms 7892 KB Output is correct
64 Correct 52 ms 9808 KB Output is correct
65 Correct 46 ms 6168 KB Output is correct
66 Correct 46 ms 7004 KB Output is correct
67 Correct 52 ms 8972 KB Output is correct
68 Correct 51 ms 10324 KB Output is correct
69 Execution timed out 2079 ms 12636 KB Time limit exceeded
70 Halted 0 ms 0 KB -