답안 #1049293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049293 2024-08-08T16:00:47 Z windowwife Joker (BOI20_joker) C++17
100 / 100
141 ms 14544 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';
    }
}
# 결과 실행 시간 메모리 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 1 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 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 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 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 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 4472 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
# 결과 실행 시간 메모리 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 1 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 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 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 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 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 4472 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 1 ms 4700 KB Output is correct
38 Correct 2 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 2 ms 4440 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 4440 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 111 ms 10708 KB Output is correct
4 Correct 90 ms 14544 KB Output is correct
5 Correct 61 ms 13000 KB Output is correct
6 Correct 64 ms 10448 KB Output is correct
7 Correct 64 ms 9420 KB Output is correct
8 Correct 63 ms 8132 KB Output is correct
9 Correct 83 ms 10452 KB Output is correct
10 Correct 103 ms 10452 KB Output is correct
11 Correct 89 ms 9424 KB Output is correct
12 Correct 91 ms 9680 KB Output is correct
13 Correct 72 ms 6656 KB Output is correct
14 Correct 71 ms 7876 KB Output is correct
15 Correct 102 ms 10708 KB Output is correct
16 Correct 105 ms 9928 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 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 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 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 4472 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 111 ms 10708 KB Output is correct
30 Correct 90 ms 14544 KB Output is correct
31 Correct 61 ms 13000 KB Output is correct
32 Correct 64 ms 10448 KB Output is correct
33 Correct 64 ms 9420 KB Output is correct
34 Correct 63 ms 8132 KB Output is correct
35 Correct 83 ms 10452 KB Output is correct
36 Correct 103 ms 10452 KB Output is correct
37 Correct 89 ms 9424 KB Output is correct
38 Correct 91 ms 9680 KB Output is correct
39 Correct 72 ms 6656 KB Output is correct
40 Correct 71 ms 7876 KB Output is correct
41 Correct 102 ms 10708 KB Output is correct
42 Correct 105 ms 9928 KB Output is correct
43 Correct 115 ms 9684 KB Output is correct
44 Correct 96 ms 14032 KB Output is correct
45 Correct 117 ms 13004 KB Output is correct
46 Correct 60 ms 10696 KB Output is correct
47 Correct 62 ms 10696 KB Output is correct
48 Correct 86 ms 10452 KB Output is correct
49 Correct 115 ms 9728 KB Output is correct
50 Correct 85 ms 10452 KB Output is correct
51 Correct 93 ms 10228 KB Output is correct
52 Correct 103 ms 10452 KB Output is correct
53 Correct 76 ms 6864 KB Output is correct
54 Correct 86 ms 10440 KB Output is correct
55 Correct 98 ms 10448 KB Output is correct
56 Correct 110 ms 10452 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 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 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 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 4472 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 1 ms 4700 KB Output is correct
38 Correct 2 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 2 ms 4440 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 4440 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4700 KB Output is correct
55 Correct 91 ms 9416 KB Output is correct
56 Correct 69 ms 13252 KB Output is correct
57 Correct 39 ms 13508 KB Output is correct
58 Correct 43 ms 9936 KB Output is correct
59 Correct 63 ms 10508 KB Output is correct
60 Correct 93 ms 9428 KB Output is correct
61 Correct 83 ms 9680 KB Output is correct
62 Correct 72 ms 9676 KB Output is correct
63 Correct 53 ms 6872 KB Output is correct
64 Correct 91 ms 9672 KB Output is correct
65 Correct 98 ms 10952 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 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 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 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 4472 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 1 ms 4700 KB Output is correct
38 Correct 2 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 2 ms 4440 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 4440 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4700 KB Output is correct
55 Correct 111 ms 10708 KB Output is correct
56 Correct 90 ms 14544 KB Output is correct
57 Correct 61 ms 13000 KB Output is correct
58 Correct 64 ms 10448 KB Output is correct
59 Correct 64 ms 9420 KB Output is correct
60 Correct 63 ms 8132 KB Output is correct
61 Correct 83 ms 10452 KB Output is correct
62 Correct 103 ms 10452 KB Output is correct
63 Correct 89 ms 9424 KB Output is correct
64 Correct 91 ms 9680 KB Output is correct
65 Correct 72 ms 6656 KB Output is correct
66 Correct 71 ms 7876 KB Output is correct
67 Correct 102 ms 10708 KB Output is correct
68 Correct 105 ms 9928 KB Output is correct
69 Correct 115 ms 9684 KB Output is correct
70 Correct 96 ms 14032 KB Output is correct
71 Correct 117 ms 13004 KB Output is correct
72 Correct 60 ms 10696 KB Output is correct
73 Correct 62 ms 10696 KB Output is correct
74 Correct 86 ms 10452 KB Output is correct
75 Correct 115 ms 9728 KB Output is correct
76 Correct 85 ms 10452 KB Output is correct
77 Correct 93 ms 10228 KB Output is correct
78 Correct 103 ms 10452 KB Output is correct
79 Correct 76 ms 6864 KB Output is correct
80 Correct 86 ms 10440 KB Output is correct
81 Correct 98 ms 10448 KB Output is correct
82 Correct 110 ms 10452 KB Output is correct
83 Correct 91 ms 9416 KB Output is correct
84 Correct 69 ms 13252 KB Output is correct
85 Correct 39 ms 13508 KB Output is correct
86 Correct 43 ms 9936 KB Output is correct
87 Correct 63 ms 10508 KB Output is correct
88 Correct 93 ms 9428 KB Output is correct
89 Correct 83 ms 9680 KB Output is correct
90 Correct 72 ms 9676 KB Output is correct
91 Correct 53 ms 6872 KB Output is correct
92 Correct 91 ms 9672 KB Output is correct
93 Correct 98 ms 10952 KB Output is correct
94 Correct 115 ms 10452 KB Output is correct
95 Correct 137 ms 14280 KB Output is correct
96 Correct 63 ms 14544 KB Output is correct
97 Correct 71 ms 9928 KB Output is correct
98 Correct 71 ms 9684 KB Output is correct
99 Correct 81 ms 8132 KB Output is correct
100 Correct 101 ms 10196 KB Output is correct
101 Correct 88 ms 9740 KB Output is correct
102 Correct 101 ms 9192 KB Output is correct
103 Correct 141 ms 10172 KB Output is correct
104 Correct 82 ms 7624 KB Output is correct
105 Correct 101 ms 10196 KB Output is correct
106 Correct 117 ms 10192 KB Output is correct
107 Correct 76 ms 14332 KB Output is correct
108 Correct 119 ms 9992 KB Output is correct
109 Correct 127 ms 10496 KB Output is correct
110 Correct 116 ms 10244 KB Output is correct
111 Correct 140 ms 10716 KB Output is correct
112 Correct 119 ms 9616 KB Output is correct
113 Correct 119 ms 9728 KB Output is correct
114 Correct 118 ms 10496 KB Output is correct
115 Correct 115 ms 9724 KB Output is correct
116 Correct 124 ms 9468 KB Output is correct