Submission #689323

# Submission time Handle Problem Language Result Execution time Memory
689323 2023-01-28T07:22:16 Z saayan007 Joker (BOI20_joker) C++17
39 / 100
2000 ms 18020 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
using vi = vector<int>;
using vl = vector<long long>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<long long, long long>>;

#define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i)
#define fr first 
#define sc second
#define mp make_pair
#define pb emplace_back
#define nl "\n"
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const ll mxn = 2e5L + 1;
ll n, m, Q;
vpl adj[mxn];
bool vis[mxn] = {};
ll dep[mxn] = {};

struct Query {
    ll l, r, idx;
};

inline bool operator<(Query &lt, Query &rt) {
    if(lt.l != rt.l)
        return lt.l < rt.l;
    return lt.r > rt.r;
}

struct UFDS {
    vl sz;
    vl lnk;
    vl ene;

    UFDS(ll N) {
        sz = vl(N, 1);
        lnk = vl(N);
        iota(all(lnk), 0);
        ene = vl(N, -1);
    }

    ll find(ll a) {
        if(a == lnk[a]) {
            return a;
        }

        return lnk[a] = find(lnk[a]);
    }

    bool same(ll a, ll b) {
        return find(a) == find(b);
    }

    ll unite(ll a, ll b) {
        a = find(a);
        b = find(b);

        if(a == b)
            return a;

        if(sz[a] < sz[b])
            swap(a, b);

        lnk[b] = a;
        sz[a] += sz[b];

        return a;
    }

    bool makeEne(ll a, ll b) {
        a = find(a);
        b = find(b);

        if(a == b) {
            return 0;
        }
        if(ene[a] == b) {
            return 1;
        }

        ll c = ene[a];
        ll d = ene[b];

        if(d != -1)
            a = unite(a, d);
        if(c != -1)
            b = unite(b, c);

        ene[a] = b;
        ene[b] = a;

        return 1;
    }
};

int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m >> Q;
    pl edge[m + 1];
    fur(i, 1, m) {
        cin >> edge[i].fr >> edge[i].sc;
    }

    Query q[Q];
    fur(rep, 0, Q - 1) {
        cin >> q[rep].l >> q[rep].r;
        q[rep].idx = rep;
    }

    bool ans[Q] = {};
    sort(q, q + Q);
    fur(i, 0, Q - 1) {
        ll j = i;
        while(j + 1 < Q && q[j + 1].l == q[i].l) {
            ++j;
        }

        bool yes = 0;
        UFDS uf(n + 1);
        fur(x, 1, q[i].l - 1) {
            yes |= !uf.makeEne(edge[x].fr, edge[x].sc);
        }

        ll cur_r = m;
        fur(x, i, j) {
            while(cur_r > q[x].r) {
                yes |= !uf.makeEne(edge[cur_r].fr, edge[cur_r].sc);
                --cur_r;
            } 
            ans[q[x].idx] = yes;
        }
        i = j;
    }

    for(auto u : ans) {
        cout << (u ? "YES" : "NO") << nl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 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 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 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 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 5 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 5032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 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 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 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 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 5 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 5032 KB Output is correct
29 Correct 17 ms 5076 KB Output is correct
30 Correct 32 ms 5076 KB Output is correct
31 Correct 37 ms 5124 KB Output is correct
32 Correct 26 ms 5112 KB Output is correct
33 Correct 24 ms 5004 KB Output is correct
34 Correct 38 ms 5140 KB Output is correct
35 Correct 35 ms 5076 KB Output is correct
36 Correct 25 ms 5140 KB Output is correct
37 Correct 43 ms 5076 KB Output is correct
38 Correct 48 ms 5132 KB Output is correct
39 Correct 34 ms 5140 KB Output is correct
40 Correct 26 ms 5136 KB Output is correct
41 Correct 27 ms 5076 KB Output is correct
42 Correct 26 ms 5076 KB Output is correct
43 Correct 30 ms 5128 KB Output is correct
44 Correct 36 ms 5116 KB Output is correct
45 Correct 44 ms 5136 KB Output is correct
46 Correct 53 ms 5076 KB Output is correct
47 Correct 25 ms 5120 KB Output is correct
48 Correct 29 ms 5076 KB Output is correct
49 Correct 36 ms 5144 KB Output is correct
50 Correct 39 ms 5136 KB Output is correct
51 Correct 23 ms 5112 KB Output is correct
52 Correct 25 ms 5128 KB Output is correct
53 Correct 31 ms 5120 KB Output is correct
54 Correct 37 ms 5148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 85 ms 15304 KB Output is correct
4 Correct 88 ms 17624 KB Output is correct
5 Correct 102 ms 17356 KB Output is correct
6 Correct 119 ms 15400 KB Output is correct
7 Correct 83 ms 15352 KB Output is correct
8 Correct 76 ms 14424 KB Output is correct
9 Correct 80 ms 15308 KB Output is correct
10 Correct 90 ms 17640 KB Output is correct
11 Correct 89 ms 15320 KB Output is correct
12 Correct 98 ms 17240 KB Output is correct
13 Correct 77 ms 13672 KB Output is correct
14 Correct 84 ms 14444 KB Output is correct
15 Correct 101 ms 16340 KB Output is correct
16 Correct 100 ms 17644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 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 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 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 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 5 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 5032 KB Output is correct
29 Correct 85 ms 15304 KB Output is correct
30 Correct 88 ms 17624 KB Output is correct
31 Correct 102 ms 17356 KB Output is correct
32 Correct 119 ms 15400 KB Output is correct
33 Correct 83 ms 15352 KB Output is correct
34 Correct 76 ms 14424 KB Output is correct
35 Correct 80 ms 15308 KB Output is correct
36 Correct 90 ms 17640 KB Output is correct
37 Correct 89 ms 15320 KB Output is correct
38 Correct 98 ms 17240 KB Output is correct
39 Correct 77 ms 13672 KB Output is correct
40 Correct 84 ms 14444 KB Output is correct
41 Correct 101 ms 16340 KB Output is correct
42 Correct 100 ms 17644 KB Output is correct
43 Correct 1031 ms 15620 KB Output is correct
44 Correct 1898 ms 18020 KB Output is correct
45 Execution timed out 2053 ms 18012 KB Time limit exceeded
46 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 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 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 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 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 5 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 5032 KB Output is correct
29 Correct 17 ms 5076 KB Output is correct
30 Correct 32 ms 5076 KB Output is correct
31 Correct 37 ms 5124 KB Output is correct
32 Correct 26 ms 5112 KB Output is correct
33 Correct 24 ms 5004 KB Output is correct
34 Correct 38 ms 5140 KB Output is correct
35 Correct 35 ms 5076 KB Output is correct
36 Correct 25 ms 5140 KB Output is correct
37 Correct 43 ms 5076 KB Output is correct
38 Correct 48 ms 5132 KB Output is correct
39 Correct 34 ms 5140 KB Output is correct
40 Correct 26 ms 5136 KB Output is correct
41 Correct 27 ms 5076 KB Output is correct
42 Correct 26 ms 5076 KB Output is correct
43 Correct 30 ms 5128 KB Output is correct
44 Correct 36 ms 5116 KB Output is correct
45 Correct 44 ms 5136 KB Output is correct
46 Correct 53 ms 5076 KB Output is correct
47 Correct 25 ms 5120 KB Output is correct
48 Correct 29 ms 5076 KB Output is correct
49 Correct 36 ms 5144 KB Output is correct
50 Correct 39 ms 5136 KB Output is correct
51 Correct 23 ms 5112 KB Output is correct
52 Correct 25 ms 5128 KB Output is correct
53 Correct 31 ms 5120 KB Output is correct
54 Correct 37 ms 5148 KB Output is correct
55 Execution timed out 2054 ms 11100 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 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 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 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 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 5 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 5032 KB Output is correct
29 Correct 17 ms 5076 KB Output is correct
30 Correct 32 ms 5076 KB Output is correct
31 Correct 37 ms 5124 KB Output is correct
32 Correct 26 ms 5112 KB Output is correct
33 Correct 24 ms 5004 KB Output is correct
34 Correct 38 ms 5140 KB Output is correct
35 Correct 35 ms 5076 KB Output is correct
36 Correct 25 ms 5140 KB Output is correct
37 Correct 43 ms 5076 KB Output is correct
38 Correct 48 ms 5132 KB Output is correct
39 Correct 34 ms 5140 KB Output is correct
40 Correct 26 ms 5136 KB Output is correct
41 Correct 27 ms 5076 KB Output is correct
42 Correct 26 ms 5076 KB Output is correct
43 Correct 30 ms 5128 KB Output is correct
44 Correct 36 ms 5116 KB Output is correct
45 Correct 44 ms 5136 KB Output is correct
46 Correct 53 ms 5076 KB Output is correct
47 Correct 25 ms 5120 KB Output is correct
48 Correct 29 ms 5076 KB Output is correct
49 Correct 36 ms 5144 KB Output is correct
50 Correct 39 ms 5136 KB Output is correct
51 Correct 23 ms 5112 KB Output is correct
52 Correct 25 ms 5128 KB Output is correct
53 Correct 31 ms 5120 KB Output is correct
54 Correct 37 ms 5148 KB Output is correct
55 Correct 85 ms 15304 KB Output is correct
56 Correct 88 ms 17624 KB Output is correct
57 Correct 102 ms 17356 KB Output is correct
58 Correct 119 ms 15400 KB Output is correct
59 Correct 83 ms 15352 KB Output is correct
60 Correct 76 ms 14424 KB Output is correct
61 Correct 80 ms 15308 KB Output is correct
62 Correct 90 ms 17640 KB Output is correct
63 Correct 89 ms 15320 KB Output is correct
64 Correct 98 ms 17240 KB Output is correct
65 Correct 77 ms 13672 KB Output is correct
66 Correct 84 ms 14444 KB Output is correct
67 Correct 101 ms 16340 KB Output is correct
68 Correct 100 ms 17644 KB Output is correct
69 Correct 1031 ms 15620 KB Output is correct
70 Correct 1898 ms 18020 KB Output is correct
71 Execution timed out 2053 ms 18012 KB Time limit exceeded
72 Halted 0 ms 0 KB -