Submission #1049262

# Submission time Handle Problem Language Result Execution time Memory
1049262 2024-08-08T15:38:09 Z windowwife Joker (BOI20_joker) C++17
100 / 100
125 ms 19324 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); 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 + 1); 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(0, m - 1, m + 1);
    while (q--)
    {
        cin >> l >> r;
        cout << (r < max_r[l - 1] ? "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 1 ms 4444 KB Output is correct
4 Correct 0 ms 4560 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 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 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 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 0 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 0 ms 4444 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 1 ms 4444 KB Output is correct
4 Correct 0 ms 4560 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 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 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 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 0 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 0 ms 4444 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 4676 KB Output is correct
30 Correct 1 ms 4580 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 2 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4580 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 4696 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 2 ms 4748 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 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 2 ms 4620 KB Output is correct
53 Correct 1 ms 4700 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 112 ms 13760 KB Output is correct
4 Correct 93 ms 16328 KB Output is correct
5 Correct 71 ms 18100 KB Output is correct
6 Correct 65 ms 13248 KB Output is correct
7 Correct 66 ms 13248 KB Output is correct
8 Correct 68 ms 11364 KB Output is correct
9 Correct 75 ms 13020 KB Output is correct
10 Correct 116 ms 13152 KB Output is correct
11 Correct 87 ms 12916 KB Output is correct
12 Correct 92 ms 13756 KB Output is correct
13 Correct 71 ms 10700 KB Output is correct
14 Correct 80 ms 11976 KB Output is correct
15 Correct 102 ms 13244 KB Output is correct
16 Correct 106 ms 13504 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 1 ms 4444 KB Output is correct
4 Correct 0 ms 4560 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 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 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 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 0 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 0 ms 4444 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 112 ms 13760 KB Output is correct
30 Correct 93 ms 16328 KB Output is correct
31 Correct 71 ms 18100 KB Output is correct
32 Correct 65 ms 13248 KB Output is correct
33 Correct 66 ms 13248 KB Output is correct
34 Correct 68 ms 11364 KB Output is correct
35 Correct 75 ms 13020 KB Output is correct
36 Correct 116 ms 13152 KB Output is correct
37 Correct 87 ms 12916 KB Output is correct
38 Correct 92 ms 13756 KB Output is correct
39 Correct 71 ms 10700 KB Output is correct
40 Correct 80 ms 11976 KB Output is correct
41 Correct 102 ms 13244 KB Output is correct
42 Correct 106 ms 13504 KB Output is correct
43 Correct 111 ms 13504 KB Output is correct
44 Correct 94 ms 17356 KB Output is correct
45 Correct 116 ms 17080 KB Output is correct
46 Correct 59 ms 14264 KB Output is correct
47 Correct 64 ms 13756 KB Output is correct
48 Correct 84 ms 12732 KB Output is correct
49 Correct 111 ms 13596 KB Output is correct
50 Correct 88 ms 13028 KB Output is correct
51 Correct 93 ms 13552 KB Output is correct
52 Correct 104 ms 14528 KB Output is correct
53 Correct 72 ms 10956 KB Output is correct
54 Correct 89 ms 13148 KB Output is correct
55 Correct 99 ms 14012 KB Output is correct
56 Correct 116 ms 13756 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 1 ms 4444 KB Output is correct
4 Correct 0 ms 4560 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 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 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 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 0 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 0 ms 4444 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 4676 KB Output is correct
30 Correct 1 ms 4580 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 2 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4580 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 4696 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 2 ms 4748 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 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 2 ms 4620 KB Output is correct
53 Correct 1 ms 4700 KB Output is correct
54 Correct 1 ms 4700 KB Output is correct
55 Correct 91 ms 12500 KB Output is correct
56 Correct 71 ms 16588 KB Output is correct
57 Correct 39 ms 15524 KB Output is correct
58 Correct 45 ms 12748 KB Output is correct
59 Correct 63 ms 11728 KB Output is correct
60 Correct 91 ms 13000 KB Output is correct
61 Correct 77 ms 11720 KB Output is correct
62 Correct 78 ms 11976 KB Output is correct
63 Correct 45 ms 9164 KB Output is correct
64 Correct 72 ms 13012 KB Output is correct
65 Correct 91 ms 12752 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 1 ms 4444 KB Output is correct
4 Correct 0 ms 4560 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 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 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 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 0 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 0 ms 4444 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 4676 KB Output is correct
30 Correct 1 ms 4580 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 2 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4580 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 4696 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 2 ms 4748 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 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 2 ms 4620 KB Output is correct
53 Correct 1 ms 4700 KB Output is correct
54 Correct 1 ms 4700 KB Output is correct
55 Correct 112 ms 13760 KB Output is correct
56 Correct 93 ms 16328 KB Output is correct
57 Correct 71 ms 18100 KB Output is correct
58 Correct 65 ms 13248 KB Output is correct
59 Correct 66 ms 13248 KB Output is correct
60 Correct 68 ms 11364 KB Output is correct
61 Correct 75 ms 13020 KB Output is correct
62 Correct 116 ms 13152 KB Output is correct
63 Correct 87 ms 12916 KB Output is correct
64 Correct 92 ms 13756 KB Output is correct
65 Correct 71 ms 10700 KB Output is correct
66 Correct 80 ms 11976 KB Output is correct
67 Correct 102 ms 13244 KB Output is correct
68 Correct 106 ms 13504 KB Output is correct
69 Correct 111 ms 13504 KB Output is correct
70 Correct 94 ms 17356 KB Output is correct
71 Correct 116 ms 17080 KB Output is correct
72 Correct 59 ms 14264 KB Output is correct
73 Correct 64 ms 13756 KB Output is correct
74 Correct 84 ms 12732 KB Output is correct
75 Correct 111 ms 13596 KB Output is correct
76 Correct 88 ms 13028 KB Output is correct
77 Correct 93 ms 13552 KB Output is correct
78 Correct 104 ms 14528 KB Output is correct
79 Correct 72 ms 10956 KB Output is correct
80 Correct 89 ms 13148 KB Output is correct
81 Correct 99 ms 14012 KB Output is correct
82 Correct 116 ms 13756 KB Output is correct
83 Correct 91 ms 12500 KB Output is correct
84 Correct 71 ms 16588 KB Output is correct
85 Correct 39 ms 15524 KB Output is correct
86 Correct 45 ms 12748 KB Output is correct
87 Correct 63 ms 11728 KB Output is correct
88 Correct 91 ms 13000 KB Output is correct
89 Correct 77 ms 11720 KB Output is correct
90 Correct 78 ms 11976 KB Output is correct
91 Correct 45 ms 9164 KB Output is correct
92 Correct 72 ms 13012 KB Output is correct
93 Correct 91 ms 12752 KB Output is correct
94 Correct 118 ms 14416 KB Output is correct
95 Correct 125 ms 19324 KB Output is correct
96 Correct 64 ms 18360 KB Output is correct
97 Correct 66 ms 15036 KB Output is correct
98 Correct 72 ms 14272 KB Output is correct
99 Correct 77 ms 13000 KB Output is correct
100 Correct 109 ms 14560 KB Output is correct
101 Correct 94 ms 14384 KB Output is correct
102 Correct 103 ms 14680 KB Output is correct
103 Correct 113 ms 15160 KB Output is correct
104 Correct 76 ms 12340 KB Output is correct
105 Correct 99 ms 15180 KB Output is correct
106 Correct 118 ms 14524 KB Output is correct
107 Correct 76 ms 18252 KB Output is correct
108 Correct 114 ms 14596 KB Output is correct
109 Correct 120 ms 14164 KB Output is correct
110 Correct 113 ms 14016 KB Output is correct
111 Correct 119 ms 14196 KB Output is correct
112 Correct 114 ms 14016 KB Output is correct
113 Correct 113 ms 14560 KB Output is correct
114 Correct 114 ms 14012 KB Output is correct
115 Correct 118 ms 14816 KB Output is correct
116 Correct 113 ms 14896 KB Output is correct