Submission #1042597

# Submission time Handle Problem Language Result Execution time Memory
1042597 2024-08-03T08:17:18 Z Neco_arc Joker (BOI20_joker) C++17
100 / 100
208 ms 17152 KB
#include <bits/stdc++.h>
#ifdef LOCAL
#include <bits/debug.hpp>
#endif // LOCAL

#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Joker"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7

using namespace std;

const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r)(rng);
}

int n, m, q;
int f[maxn];
pair<int, int> qr[maxn];
struct dl { int u, v; } a[maxn];

struct DSU {
    int lab[maxn], col[maxn], bad;
    vector<pair<int, int>> E;
    int *addr[6 * maxn], val[6 * maxn], top;

    DSU() { memset(lab, -1, sizeof lab); }

    void Add(int *a, int b) { if(*a != b) addr[++top] = a, val[top] = *a, *a = b; }
    void RollBack(int Time) { while(top > Time)  *addr[top] = val[top], --top; }


    int get_rt(int u) {
        return lab[u] < 0 ? u : get_rt(lab[u]);
    }

    int cl(int u) {
        return lab[u] < 0 ? col[u] : (col[u] ^ cl(lab[u]));
    }

    void uni(int u, int v) {
        int p = get_rt(u), q = get_rt(v);
        if(p == q) {
            Add(&bad, bad | (cl(u) == cl(v)));
            return;
        }

        if(lab[p] > lab[q]) swap(p, q);
        Add(&col[q], col[q] ^ (cl(u) == cl(v)));
        Add(&lab[p], lab[p] + lab[q]), Add(&lab[q], p);
    }

} Dsu;

/// 1 -> optL and r + 1 -> n already in DSU
void DnC(int l, int r, int optL, int optR) {
    if(l > r) return;
    int mid = (l + r) >> 1, pos = mid;

    int Time = Dsu.top;
    fid(i, r, mid + 1) Dsu.uni(a[i].u, a[i].v);

    fi(i, optL, min(mid, optR)) {
        if(i) Dsu.uni(a[i].u, a[i].v);
        if(Dsu.bad) { pos = i; break; }
    }

    f[mid] = pos;

    Dsu.RollBack(Time);
    fid(i, r, mid) Dsu.uni(a[i].u, a[i].v);
    DnC(l, mid - 1, optL, pos);

    Dsu.RollBack(Time);
    fi(i, optL, pos - 1) if(i) Dsu.uni(a[i].u, a[i].v);
    DnC(mid + 1, r, pos, optR);

    Dsu.RollBack(Time);
}


void solve()
{

    cin >> n >> m >> q;
    fi(i, 1, m) cin >> a[i].u >> a[i].v;

    DnC(1, m, 0, m);

    fi(i, 1, q) {
        int l, r; cin >> l >> r;
        cout << (l > f[r] ? "YES\n" : "NO\n");
    }

}


int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen(Neco".inp", "r")) {
        freopen(Neco".inp", "r", stdin);
        freopen(Neco".out", "w", stdout);
    }


    int nTest = 1;
//    cin >> nTest;


    while(nTest--)
    {
        solve();
    }


    return 0;
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:118:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |         freopen(Neco".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 0 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1256 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 0 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1160 KB Output is correct
22 Correct 1 ms 1120 KB Output is correct
23 Correct 1 ms 1120 KB Output is correct
24 Correct 0 ms 1124 KB Output is correct
25 Correct 1 ms 1120 KB Output is correct
26 Correct 0 ms 1124 KB Output is correct
27 Correct 1 ms 1120 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 0 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1256 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 0 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1160 KB Output is correct
22 Correct 1 ms 1120 KB Output is correct
23 Correct 1 ms 1120 KB Output is correct
24 Correct 0 ms 1124 KB Output is correct
25 Correct 1 ms 1120 KB Output is correct
26 Correct 0 ms 1124 KB Output is correct
27 Correct 1 ms 1120 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 2 ms 1376 KB Output is correct
31 Correct 2 ms 1376 KB Output is correct
32 Correct 1 ms 1372 KB Output is correct
33 Correct 2 ms 1368 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
35 Correct 3 ms 1372 KB Output is correct
36 Correct 1 ms 1368 KB Output is correct
37 Correct 2 ms 1372 KB Output is correct
38 Correct 3 ms 2656 KB Output is correct
39 Correct 2 ms 1408 KB Output is correct
40 Correct 1 ms 1376 KB Output is correct
41 Correct 2 ms 1372 KB Output is correct
42 Correct 1 ms 1376 KB Output is correct
43 Correct 1 ms 2656 KB Output is correct
44 Correct 2 ms 1352 KB Output is correct
45 Correct 2 ms 1372 KB Output is correct
46 Correct 1 ms 1372 KB Output is correct
47 Correct 2 ms 1264 KB Output is correct
48 Correct 1 ms 1372 KB Output is correct
49 Correct 2 ms 1264 KB Output is correct
50 Correct 2 ms 1372 KB Output is correct
51 Correct 1 ms 1120 KB Output is correct
52 Correct 2 ms 2648 KB Output is correct
53 Correct 2 ms 1396 KB Output is correct
54 Correct 2 ms 1268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 136 ms 11344 KB Output is correct
4 Correct 180 ms 14616 KB Output is correct
5 Correct 130 ms 14932 KB Output is correct
6 Correct 138 ms 11856 KB Output is correct
7 Correct 152 ms 11604 KB Output is correct
8 Correct 142 ms 9580 KB Output is correct
9 Correct 159 ms 11132 KB Output is correct
10 Correct 198 ms 13908 KB Output is correct
11 Correct 146 ms 11480 KB Output is correct
12 Correct 157 ms 13996 KB Output is correct
13 Correct 130 ms 9584 KB Output is correct
14 Correct 142 ms 10084 KB Output is correct
15 Correct 180 ms 12728 KB Output is correct
16 Correct 208 ms 14160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 0 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1256 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 0 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1160 KB Output is correct
22 Correct 1 ms 1120 KB Output is correct
23 Correct 1 ms 1120 KB Output is correct
24 Correct 0 ms 1124 KB Output is correct
25 Correct 1 ms 1120 KB Output is correct
26 Correct 0 ms 1124 KB Output is correct
27 Correct 1 ms 1120 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 136 ms 11344 KB Output is correct
30 Correct 180 ms 14616 KB Output is correct
31 Correct 130 ms 14932 KB Output is correct
32 Correct 138 ms 11856 KB Output is correct
33 Correct 152 ms 11604 KB Output is correct
34 Correct 142 ms 9580 KB Output is correct
35 Correct 159 ms 11132 KB Output is correct
36 Correct 198 ms 13908 KB Output is correct
37 Correct 146 ms 11480 KB Output is correct
38 Correct 157 ms 13996 KB Output is correct
39 Correct 130 ms 9584 KB Output is correct
40 Correct 142 ms 10084 KB Output is correct
41 Correct 180 ms 12728 KB Output is correct
42 Correct 208 ms 14160 KB Output is correct
43 Correct 108 ms 11884 KB Output is correct
44 Correct 180 ms 14968 KB Output is correct
45 Correct 129 ms 15440 KB Output is correct
46 Correct 116 ms 12372 KB Output is correct
47 Correct 159 ms 12048 KB Output is correct
48 Correct 165 ms 11504 KB Output is correct
49 Correct 196 ms 14164 KB Output is correct
50 Correct 161 ms 11600 KB Output is correct
51 Correct 137 ms 13404 KB Output is correct
52 Correct 144 ms 14672 KB Output is correct
53 Correct 122 ms 9812 KB Output is correct
54 Correct 153 ms 11760 KB Output is correct
55 Correct 188 ms 13396 KB Output is correct
56 Correct 197 ms 14424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 0 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1256 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 0 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1160 KB Output is correct
22 Correct 1 ms 1120 KB Output is correct
23 Correct 1 ms 1120 KB Output is correct
24 Correct 0 ms 1124 KB Output is correct
25 Correct 1 ms 1120 KB Output is correct
26 Correct 0 ms 1124 KB Output is correct
27 Correct 1 ms 1120 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 2 ms 1376 KB Output is correct
31 Correct 2 ms 1376 KB Output is correct
32 Correct 1 ms 1372 KB Output is correct
33 Correct 2 ms 1368 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
35 Correct 3 ms 1372 KB Output is correct
36 Correct 1 ms 1368 KB Output is correct
37 Correct 2 ms 1372 KB Output is correct
38 Correct 3 ms 2656 KB Output is correct
39 Correct 2 ms 1408 KB Output is correct
40 Correct 1 ms 1376 KB Output is correct
41 Correct 2 ms 1372 KB Output is correct
42 Correct 1 ms 1376 KB Output is correct
43 Correct 1 ms 2656 KB Output is correct
44 Correct 2 ms 1352 KB Output is correct
45 Correct 2 ms 1372 KB Output is correct
46 Correct 1 ms 1372 KB Output is correct
47 Correct 2 ms 1264 KB Output is correct
48 Correct 1 ms 1372 KB Output is correct
49 Correct 2 ms 1264 KB Output is correct
50 Correct 2 ms 1372 KB Output is correct
51 Correct 1 ms 1120 KB Output is correct
52 Correct 2 ms 2648 KB Output is correct
53 Correct 2 ms 1396 KB Output is correct
54 Correct 2 ms 1268 KB Output is correct
55 Correct 87 ms 9040 KB Output is correct
56 Correct 153 ms 12884 KB Output is correct
57 Correct 114 ms 12372 KB Output is correct
58 Correct 99 ms 9556 KB Output is correct
59 Correct 152 ms 9300 KB Output is correct
60 Correct 169 ms 11092 KB Output is correct
61 Correct 124 ms 9044 KB Output is correct
62 Correct 142 ms 11364 KB Output is correct
63 Correct 113 ms 7760 KB Output is correct
64 Correct 149 ms 9940 KB Output is correct
65 Correct 162 ms 11788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 0 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1256 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 0 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1160 KB Output is correct
22 Correct 1 ms 1120 KB Output is correct
23 Correct 1 ms 1120 KB Output is correct
24 Correct 0 ms 1124 KB Output is correct
25 Correct 1 ms 1120 KB Output is correct
26 Correct 0 ms 1124 KB Output is correct
27 Correct 1 ms 1120 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 2 ms 1376 KB Output is correct
31 Correct 2 ms 1376 KB Output is correct
32 Correct 1 ms 1372 KB Output is correct
33 Correct 2 ms 1368 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
35 Correct 3 ms 1372 KB Output is correct
36 Correct 1 ms 1368 KB Output is correct
37 Correct 2 ms 1372 KB Output is correct
38 Correct 3 ms 2656 KB Output is correct
39 Correct 2 ms 1408 KB Output is correct
40 Correct 1 ms 1376 KB Output is correct
41 Correct 2 ms 1372 KB Output is correct
42 Correct 1 ms 1376 KB Output is correct
43 Correct 1 ms 2656 KB Output is correct
44 Correct 2 ms 1352 KB Output is correct
45 Correct 2 ms 1372 KB Output is correct
46 Correct 1 ms 1372 KB Output is correct
47 Correct 2 ms 1264 KB Output is correct
48 Correct 1 ms 1372 KB Output is correct
49 Correct 2 ms 1264 KB Output is correct
50 Correct 2 ms 1372 KB Output is correct
51 Correct 1 ms 1120 KB Output is correct
52 Correct 2 ms 2648 KB Output is correct
53 Correct 2 ms 1396 KB Output is correct
54 Correct 2 ms 1268 KB Output is correct
55 Correct 136 ms 11344 KB Output is correct
56 Correct 180 ms 14616 KB Output is correct
57 Correct 130 ms 14932 KB Output is correct
58 Correct 138 ms 11856 KB Output is correct
59 Correct 152 ms 11604 KB Output is correct
60 Correct 142 ms 9580 KB Output is correct
61 Correct 159 ms 11132 KB Output is correct
62 Correct 198 ms 13908 KB Output is correct
63 Correct 146 ms 11480 KB Output is correct
64 Correct 157 ms 13996 KB Output is correct
65 Correct 130 ms 9584 KB Output is correct
66 Correct 142 ms 10084 KB Output is correct
67 Correct 180 ms 12728 KB Output is correct
68 Correct 208 ms 14160 KB Output is correct
69 Correct 108 ms 11884 KB Output is correct
70 Correct 180 ms 14968 KB Output is correct
71 Correct 129 ms 15440 KB Output is correct
72 Correct 116 ms 12372 KB Output is correct
73 Correct 159 ms 12048 KB Output is correct
74 Correct 165 ms 11504 KB Output is correct
75 Correct 196 ms 14164 KB Output is correct
76 Correct 161 ms 11600 KB Output is correct
77 Correct 137 ms 13404 KB Output is correct
78 Correct 144 ms 14672 KB Output is correct
79 Correct 122 ms 9812 KB Output is correct
80 Correct 153 ms 11760 KB Output is correct
81 Correct 188 ms 13396 KB Output is correct
82 Correct 197 ms 14424 KB Output is correct
83 Correct 87 ms 9040 KB Output is correct
84 Correct 153 ms 12884 KB Output is correct
85 Correct 114 ms 12372 KB Output is correct
86 Correct 99 ms 9556 KB Output is correct
87 Correct 152 ms 9300 KB Output is correct
88 Correct 169 ms 11092 KB Output is correct
89 Correct 124 ms 9044 KB Output is correct
90 Correct 142 ms 11364 KB Output is correct
91 Correct 113 ms 7760 KB Output is correct
92 Correct 149 ms 9940 KB Output is correct
93 Correct 162 ms 11788 KB Output is correct
94 Correct 108 ms 12796 KB Output is correct
95 Correct 170 ms 15956 KB Output is correct
96 Correct 152 ms 15584 KB Output is correct
97 Correct 142 ms 13108 KB Output is correct
98 Correct 178 ms 12628 KB Output is correct
99 Correct 141 ms 11856 KB Output is correct
100 Correct 182 ms 15232 KB Output is correct
101 Correct 140 ms 12416 KB Output is correct
102 Correct 150 ms 13648 KB Output is correct
103 Correct 166 ms 15132 KB Output is correct
104 Correct 135 ms 10580 KB Output is correct
105 Correct 180 ms 13344 KB Output is correct
106 Correct 203 ms 14928 KB Output is correct
107 Correct 76 ms 17152 KB Output is correct
108 Correct 108 ms 12600 KB Output is correct
109 Correct 118 ms 12368 KB Output is correct
110 Correct 120 ms 12368 KB Output is correct
111 Correct 110 ms 12372 KB Output is correct
112 Correct 131 ms 12372 KB Output is correct
113 Correct 114 ms 12376 KB Output is correct
114 Correct 112 ms 12360 KB Output is correct
115 Correct 111 ms 12368 KB Output is correct
116 Correct 116 ms 12740 KB Output is correct