Submission #1049296

# Submission time Handle Problem Language Result Execution time Memory
1049296 2024-08-08T16:01:31 Z vjudge1 Joker (BOI20_joker) C++17
100 / 100
128 ms 15044 KB
#include<bits/stdc++.h>
#define ll long long
#define task ""
using namespace std;
const int maxn = 4e5 + 2;
int n, m, q, max_r[maxn], u[maxn], v[maxn], l, r, par[maxn];
vector<pair<int, int>> rb;
int find_set (int u)
{
    if (par[u] < 0) return u;
    return find_set(par[u]);
}
void union_set (int u, int v)
{
    int pu = find_set(u), pv = find_set(v);
    if (pu == pv) return;
    if (par[pu] > par[pv]) swap(pu, pv);
    rb.push_back({pu, par[pu]});
    rb.push_back({pv, par[pv]});
    par[pu] += par[pv];
    par[pv] = pu;
}
void rollback ()
{
    if (rb.empty()) return;
    par[rb.back().first] = rb.back().second;
    rb.pop_back();
}
void pbs (int low, int high, int r)
{
    if (low > high) return;
    //cout << low << " " << high << " " << r << endl;
    int mid = (low + high)/2, tmp = rb.size();
    for (int i = max(low - 1, 1); i < mid; i++)
    {
        //cout << i << endl;
        union_set(u[i], v[i] + n);
        union_set(u[i] + n, v[i]);
        if (find_set(u[i]) == find_set(u[i] + n))
        {
            for (int j = mid; j <= high; j++) max_r[j] = r;
            while ((int)rb.size() > tmp) rollback();
            pbs(low, mid - 1, r);
            return;
        }
    }
    int tmp2 = rb.size();
    for (int i = r - 1; i >= low; i--)
    {
        union_set(u[i], v[i] + n);
        union_set(u[i] + n, v[i]);
        if (find_set(u[i]) == find_set(u[i] + n))
        {
            max_r[mid] = i;
            break;
        }
    }
    while ((int)rb.size() > tmp2) rollback();
    pbs(mid + 1, high, r);
    while ((int)rb.size() > tmp) rollback();
    for (int i = r - 1; i >= max(max_r[mid], low); i--)
    {
        union_set(u[i], v[i] + n);
        union_set(u[i] + n, v[i]);
        if (find_set(u[i]) == find_set(u[i] + n))
        {
            for (int j = low; j <= mid; j++) max_r[j] = max_r[mid];
            return;
        }
    }
    pbs(low, mid - 1, max_r[mid]);
}
int main ()
{
    //freopen(task".INP", "r", stdin);
    //freopen(task".OUT", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> q;
    for (int i = 1; i <= 2*n; i++) par[i] = -1;
    for (int i = 1; i <= m; i++) cin >> u[i] >> v[i];
    pbs(1, m, m + 1);
    while (q--)
    {
        cin >> l >> r;
        cout << (r < max_r[l] ? "YES" : "NO") << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4576 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 0 ms 4444 KB Output is correct
26 Correct 0 ms 4444 KB Output is correct
27 Correct 0 ms 4444 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4576 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 0 ms 4444 KB Output is correct
26 Correct 0 ms 4444 KB Output is correct
27 Correct 0 ms 4444 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 1 ms 4700 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 118 ms 9212 KB Output is correct
4 Correct 92 ms 13252 KB Output is correct
5 Correct 62 ms 14584 KB Output is correct
6 Correct 63 ms 10184 KB Output is correct
7 Correct 84 ms 9468 KB Output is correct
8 Correct 63 ms 8136 KB Output is correct
9 Correct 73 ms 9728 KB Output is correct
10 Correct 105 ms 9532 KB Output is correct
11 Correct 85 ms 9940 KB Output is correct
12 Correct 92 ms 10448 KB Output is correct
13 Correct 67 ms 6636 KB Output is correct
14 Correct 78 ms 7884 KB Output is correct
15 Correct 102 ms 9704 KB Output is correct
16 Correct 128 ms 9496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4576 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 0 ms 4444 KB Output is correct
26 Correct 0 ms 4444 KB Output is correct
27 Correct 0 ms 4444 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 118 ms 9212 KB Output is correct
30 Correct 92 ms 13252 KB Output is correct
31 Correct 62 ms 14584 KB Output is correct
32 Correct 63 ms 10184 KB Output is correct
33 Correct 84 ms 9468 KB Output is correct
34 Correct 63 ms 8136 KB Output is correct
35 Correct 73 ms 9728 KB Output is correct
36 Correct 105 ms 9532 KB Output is correct
37 Correct 85 ms 9940 KB Output is correct
38 Correct 92 ms 10448 KB Output is correct
39 Correct 67 ms 6636 KB Output is correct
40 Correct 78 ms 7884 KB Output is correct
41 Correct 102 ms 9704 KB Output is correct
42 Correct 128 ms 9496 KB Output is correct
43 Correct 112 ms 10700 KB Output is correct
44 Correct 93 ms 15044 KB Output is correct
45 Correct 117 ms 14276 KB Output is correct
46 Correct 58 ms 9676 KB Output is correct
47 Correct 65 ms 10708 KB Output is correct
48 Correct 88 ms 9160 KB Output is correct
49 Correct 107 ms 10708 KB Output is correct
50 Correct 88 ms 9428 KB Output is correct
51 Correct 92 ms 9932 KB Output is correct
52 Correct 100 ms 10708 KB Output is correct
53 Correct 70 ms 6856 KB Output is correct
54 Correct 91 ms 10444 KB Output is correct
55 Correct 98 ms 10696 KB Output is correct
56 Correct 111 ms 9504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4576 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 0 ms 4444 KB Output is correct
26 Correct 0 ms 4444 KB Output is correct
27 Correct 0 ms 4444 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 1 ms 4700 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4700 KB Output is correct
55 Correct 90 ms 10704 KB Output is correct
56 Correct 70 ms 14836 KB Output is correct
57 Correct 39 ms 13776 KB Output is correct
58 Correct 55 ms 10708 KB Output is correct
59 Correct 63 ms 10708 KB Output is correct
60 Correct 91 ms 9936 KB Output is correct
61 Correct 76 ms 9160 KB Output is correct
62 Correct 73 ms 9936 KB Output is correct
63 Correct 44 ms 6872 KB Output is correct
64 Correct 71 ms 10184 KB Output is correct
65 Correct 89 ms 9168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4576 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 0 ms 4444 KB Output is correct
26 Correct 0 ms 4444 KB Output is correct
27 Correct 0 ms 4444 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 1 ms 4700 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4700 KB Output is correct
55 Correct 118 ms 9212 KB Output is correct
56 Correct 92 ms 13252 KB Output is correct
57 Correct 62 ms 14584 KB Output is correct
58 Correct 63 ms 10184 KB Output is correct
59 Correct 84 ms 9468 KB Output is correct
60 Correct 63 ms 8136 KB Output is correct
61 Correct 73 ms 9728 KB Output is correct
62 Correct 105 ms 9532 KB Output is correct
63 Correct 85 ms 9940 KB Output is correct
64 Correct 92 ms 10448 KB Output is correct
65 Correct 67 ms 6636 KB Output is correct
66 Correct 78 ms 7884 KB Output is correct
67 Correct 102 ms 9704 KB Output is correct
68 Correct 128 ms 9496 KB Output is correct
69 Correct 112 ms 10700 KB Output is correct
70 Correct 93 ms 15044 KB Output is correct
71 Correct 117 ms 14276 KB Output is correct
72 Correct 58 ms 9676 KB Output is correct
73 Correct 65 ms 10708 KB Output is correct
74 Correct 88 ms 9160 KB Output is correct
75 Correct 107 ms 10708 KB Output is correct
76 Correct 88 ms 9428 KB Output is correct
77 Correct 92 ms 9932 KB Output is correct
78 Correct 100 ms 10708 KB Output is correct
79 Correct 70 ms 6856 KB Output is correct
80 Correct 91 ms 10444 KB Output is correct
81 Correct 98 ms 10696 KB Output is correct
82 Correct 111 ms 9504 KB Output is correct
83 Correct 90 ms 10704 KB Output is correct
84 Correct 70 ms 14836 KB Output is correct
85 Correct 39 ms 13776 KB Output is correct
86 Correct 55 ms 10708 KB Output is correct
87 Correct 63 ms 10708 KB Output is correct
88 Correct 91 ms 9936 KB Output is correct
89 Correct 76 ms 9160 KB Output is correct
90 Correct 73 ms 9936 KB Output is correct
91 Correct 44 ms 6872 KB Output is correct
92 Correct 71 ms 10184 KB Output is correct
93 Correct 89 ms 9168 KB Output is correct
94 Correct 114 ms 10440 KB Output is correct
95 Correct 125 ms 13572 KB Output is correct
96 Correct 62 ms 14280 KB Output is correct
97 Correct 64 ms 10196 KB Output is correct
98 Correct 70 ms 9728 KB Output is correct
99 Correct 75 ms 8136 KB Output is correct
100 Correct 102 ms 10448 KB Output is correct
101 Correct 86 ms 9428 KB Output is correct
102 Correct 110 ms 9464 KB Output is correct
103 Correct 125 ms 9932 KB Output is correct
104 Correct 73 ms 7620 KB Output is correct
105 Correct 97 ms 10196 KB Output is correct
106 Correct 111 ms 9404 KB Output is correct
107 Correct 70 ms 13508 KB Output is correct
108 Correct 113 ms 9992 KB Output is correct
109 Correct 111 ms 9336 KB Output is correct
110 Correct 113 ms 9728 KB Output is correct
111 Correct 117 ms 10448 KB Output is correct
112 Correct 117 ms 10196 KB Output is correct
113 Correct 111 ms 9408 KB Output is correct
114 Correct 112 ms 9428 KB Output is correct
115 Correct 114 ms 9424 KB Output is correct
116 Correct 112 ms 10704 KB Output is correct