답안 #973874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973874 2024-05-02T12:12:20 Z ttttttttttttth Joker (BOI20_joker) C++17
100 / 100
272 ms 19516 KB
// Author: Ivan Teo
// Created: Thu May 02 18:44:14 2024

#define TASKNAME "joker"
#include <bits/stdc++.h>
using namespace std;

#define fore(i, a, b) for (int i = (a); i <= (b); i++)
#define int long long
using vi = vector<int>;
using ii = pair<int, int>;
#define pb emplace_back
#define fi first
#define se second
#define sz(v) ((int)v.size())
#define all(v) v.begin() + 1, v.end()
#define alll(v) v.begin(), v.end()
#define db(x) cerr << "[" << #x << " = " << x << "]"
#define el cerr << "\n=============================\n"
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int l, int r)
{
    assert(l <= r);
    return uniform_int_distribution<int> (l, r)(rng);
}

const int N = 2e5 + 5;
stack<int> ev;
int n, m, q, u[N], v[N], p[N << 1], sz[N << 1], ans[N];
bool odd;

int get(int x)
{
    while (x != p[x]) x = p[x];
    return x;
}

void uni(int u, int v)
{
    u = get(u);
    v = get(v);
    if (u == v) return ;
    if (sz[u] < sz[v]) swap(u, v);
    sz[u] += sz[v];
    p[v] = u;
    ev.push(v);
}

void roll(int x)
{
    while (sz(ev) > x)
    {
        int u = ev.top();
        ev.pop();
        if (u == -1) odd = 0;
        else sz[p[u]] -= sz[u], p[u] = u;
    }
}

void add(int a, int b)
{
    uni(a, b + n), uni(b, a + n);
    if (!odd) if (get(a) == get(a + n) || get(b) == get(b + n))
            odd = 1, ev.push(-1);
}

void dac(int l, int r, int opl, int opr)
{
    if (l > r) return ;
    int mid = l + r >> 1, snap = sz(ev);
    fore(i, l, mid - 1) add(u[i], v[i]);
    int ri = sz(ev);
    ans[mid] = -1;
    for (int i = opr; i >= max(mid, opl); i--)
    {
        if (odd)
        {
            ans[mid] = i;
            break;
        }
        add(u[i], v[i]);
    }
    if (ans[mid] == -1) ans[mid] = mid - 1;
    roll(ri);
    add(u[mid], v[mid]);
    dac(mid + 1, r, ans[mid], opr);
    roll(snap);
    for (int i = opr; i > ans[mid]; i--) add(u[i], v[i]);
    dac(l, mid - 1, opl, ans[mid]);
    roll(snap);
}

void solve()
{
    iota(p, p + (N << 1), 0);
    fill(sz, sz + (N << 1), 1);
    cin >> n >> m >> q;
    fore(i, 1, m) cin >> u[i] >> v[i];
    dac(1, m, 1, m); 
    while (q--)
    {
        int a, b; cin >> a >> b;
        cout <<  (b <= ans[a] ? "YES\n" : "NO\n");
    }
}

signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("in", "r"))
        freopen("in", "r", stdin);
    if (fopen(TASKNAME ".inp", "r"))
        freopen(TASKNAME ".inp", "r", stdin),
                freopen(TASKNAME ".out", "w", stdout);
    int tc = 1;
    // cin >> tc;
    while (tc--)
        solve();
    return 0;
}

Compilation message

Joker.cpp: In function 'void dac(long long int, long long int, long long int, long long int)':
Joker.cpp:70:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |     int mid = l + r >> 1, snap = sz(ev);
      |               ~~^~~
Joker.cpp: In function 'int main()':
Joker.cpp:111:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |         freopen("in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~
Joker.cpp:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |         freopen(TASKNAME ".inp", "r", stdin),
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:114:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |                 freopen(TASKNAME ".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10712 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10840 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 3 ms 10704 KB Output is correct
22 Correct 2 ms 10584 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 2 ms 10720 KB Output is correct
28 Correct 2 ms 10724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10712 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10840 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 3 ms 10704 KB Output is correct
22 Correct 2 ms 10584 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 2 ms 10720 KB Output is correct
28 Correct 2 ms 10724 KB Output is correct
29 Correct 3 ms 10588 KB Output is correct
30 Correct 3 ms 10744 KB Output is correct
31 Correct 3 ms 10584 KB Output is correct
32 Correct 3 ms 10588 KB Output is correct
33 Correct 3 ms 10588 KB Output is correct
34 Correct 3 ms 10584 KB Output is correct
35 Correct 3 ms 10584 KB Output is correct
36 Correct 3 ms 10740 KB Output is correct
37 Correct 3 ms 10588 KB Output is correct
38 Correct 3 ms 10588 KB Output is correct
39 Correct 3 ms 10588 KB Output is correct
40 Correct 3 ms 10588 KB Output is correct
41 Correct 4 ms 11352 KB Output is correct
42 Correct 3 ms 10584 KB Output is correct
43 Correct 3 ms 10588 KB Output is correct
44 Correct 3 ms 10588 KB Output is correct
45 Correct 3 ms 10720 KB Output is correct
46 Correct 3 ms 10588 KB Output is correct
47 Correct 3 ms 10588 KB Output is correct
48 Correct 3 ms 10668 KB Output is correct
49 Correct 3 ms 10584 KB Output is correct
50 Correct 4 ms 10584 KB Output is correct
51 Correct 3 ms 10588 KB Output is correct
52 Correct 4 ms 10896 KB Output is correct
53 Correct 4 ms 10716 KB Output is correct
54 Correct 4 ms 10584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 133 ms 17452 KB Output is correct
4 Correct 253 ms 17408 KB Output is correct
5 Correct 124 ms 18056 KB Output is correct
6 Correct 148 ms 17692 KB Output is correct
7 Correct 152 ms 17676 KB Output is correct
8 Correct 189 ms 16468 KB Output is correct
9 Correct 200 ms 16680 KB Output is correct
10 Correct 264 ms 17676 KB Output is correct
11 Correct 183 ms 17512 KB Output is correct
12 Correct 211 ms 17892 KB Output is correct
13 Correct 186 ms 16208 KB Output is correct
14 Correct 190 ms 17000 KB Output is correct
15 Correct 245 ms 17820 KB Output is correct
16 Correct 253 ms 17984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10712 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10840 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 3 ms 10704 KB Output is correct
22 Correct 2 ms 10584 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 2 ms 10720 KB Output is correct
28 Correct 2 ms 10724 KB Output is correct
29 Correct 133 ms 17452 KB Output is correct
30 Correct 253 ms 17408 KB Output is correct
31 Correct 124 ms 18056 KB Output is correct
32 Correct 148 ms 17692 KB Output is correct
33 Correct 152 ms 17676 KB Output is correct
34 Correct 189 ms 16468 KB Output is correct
35 Correct 200 ms 16680 KB Output is correct
36 Correct 264 ms 17676 KB Output is correct
37 Correct 183 ms 17512 KB Output is correct
38 Correct 211 ms 17892 KB Output is correct
39 Correct 186 ms 16208 KB Output is correct
40 Correct 190 ms 17000 KB Output is correct
41 Correct 245 ms 17820 KB Output is correct
42 Correct 253 ms 17984 KB Output is correct
43 Correct 147 ms 17704 KB Output is correct
44 Correct 240 ms 18048 KB Output is correct
45 Correct 205 ms 19516 KB Output is correct
46 Correct 137 ms 17836 KB Output is correct
47 Correct 154 ms 17888 KB Output is correct
48 Correct 216 ms 17392 KB Output is correct
49 Correct 267 ms 18100 KB Output is correct
50 Correct 179 ms 17552 KB Output is correct
51 Correct 205 ms 18180 KB Output is correct
52 Correct 215 ms 18252 KB Output is correct
53 Correct 186 ms 16424 KB Output is correct
54 Correct 238 ms 17492 KB Output is correct
55 Correct 238 ms 18436 KB Output is correct
56 Correct 266 ms 18388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10712 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10840 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 3 ms 10704 KB Output is correct
22 Correct 2 ms 10584 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 2 ms 10720 KB Output is correct
28 Correct 2 ms 10724 KB Output is correct
29 Correct 3 ms 10588 KB Output is correct
30 Correct 3 ms 10744 KB Output is correct
31 Correct 3 ms 10584 KB Output is correct
32 Correct 3 ms 10588 KB Output is correct
33 Correct 3 ms 10588 KB Output is correct
34 Correct 3 ms 10584 KB Output is correct
35 Correct 3 ms 10584 KB Output is correct
36 Correct 3 ms 10740 KB Output is correct
37 Correct 3 ms 10588 KB Output is correct
38 Correct 3 ms 10588 KB Output is correct
39 Correct 3 ms 10588 KB Output is correct
40 Correct 3 ms 10588 KB Output is correct
41 Correct 4 ms 11352 KB Output is correct
42 Correct 3 ms 10584 KB Output is correct
43 Correct 3 ms 10588 KB Output is correct
44 Correct 3 ms 10588 KB Output is correct
45 Correct 3 ms 10720 KB Output is correct
46 Correct 3 ms 10588 KB Output is correct
47 Correct 3 ms 10588 KB Output is correct
48 Correct 3 ms 10668 KB Output is correct
49 Correct 3 ms 10584 KB Output is correct
50 Correct 4 ms 10584 KB Output is correct
51 Correct 3 ms 10588 KB Output is correct
52 Correct 4 ms 10896 KB Output is correct
53 Correct 4 ms 10716 KB Output is correct
54 Correct 4 ms 10584 KB Output is correct
55 Correct 106 ms 15316 KB Output is correct
56 Correct 215 ms 17056 KB Output is correct
57 Correct 83 ms 16460 KB Output is correct
58 Correct 123 ms 15372 KB Output is correct
59 Correct 192 ms 15080 KB Output is correct
60 Correct 252 ms 16044 KB Output is correct
61 Correct 168 ms 15268 KB Output is correct
62 Correct 184 ms 16332 KB Output is correct
63 Correct 153 ms 14156 KB Output is correct
64 Correct 196 ms 15700 KB Output is correct
65 Correct 226 ms 16208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10712 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10840 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 3 ms 10704 KB Output is correct
22 Correct 2 ms 10584 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 2 ms 10720 KB Output is correct
28 Correct 2 ms 10724 KB Output is correct
29 Correct 3 ms 10588 KB Output is correct
30 Correct 3 ms 10744 KB Output is correct
31 Correct 3 ms 10584 KB Output is correct
32 Correct 3 ms 10588 KB Output is correct
33 Correct 3 ms 10588 KB Output is correct
34 Correct 3 ms 10584 KB Output is correct
35 Correct 3 ms 10584 KB Output is correct
36 Correct 3 ms 10740 KB Output is correct
37 Correct 3 ms 10588 KB Output is correct
38 Correct 3 ms 10588 KB Output is correct
39 Correct 3 ms 10588 KB Output is correct
40 Correct 3 ms 10588 KB Output is correct
41 Correct 4 ms 11352 KB Output is correct
42 Correct 3 ms 10584 KB Output is correct
43 Correct 3 ms 10588 KB Output is correct
44 Correct 3 ms 10588 KB Output is correct
45 Correct 3 ms 10720 KB Output is correct
46 Correct 3 ms 10588 KB Output is correct
47 Correct 3 ms 10588 KB Output is correct
48 Correct 3 ms 10668 KB Output is correct
49 Correct 3 ms 10584 KB Output is correct
50 Correct 4 ms 10584 KB Output is correct
51 Correct 3 ms 10588 KB Output is correct
52 Correct 4 ms 10896 KB Output is correct
53 Correct 4 ms 10716 KB Output is correct
54 Correct 4 ms 10584 KB Output is correct
55 Correct 133 ms 17452 KB Output is correct
56 Correct 253 ms 17408 KB Output is correct
57 Correct 124 ms 18056 KB Output is correct
58 Correct 148 ms 17692 KB Output is correct
59 Correct 152 ms 17676 KB Output is correct
60 Correct 189 ms 16468 KB Output is correct
61 Correct 200 ms 16680 KB Output is correct
62 Correct 264 ms 17676 KB Output is correct
63 Correct 183 ms 17512 KB Output is correct
64 Correct 211 ms 17892 KB Output is correct
65 Correct 186 ms 16208 KB Output is correct
66 Correct 190 ms 17000 KB Output is correct
67 Correct 245 ms 17820 KB Output is correct
68 Correct 253 ms 17984 KB Output is correct
69 Correct 147 ms 17704 KB Output is correct
70 Correct 240 ms 18048 KB Output is correct
71 Correct 205 ms 19516 KB Output is correct
72 Correct 137 ms 17836 KB Output is correct
73 Correct 154 ms 17888 KB Output is correct
74 Correct 216 ms 17392 KB Output is correct
75 Correct 267 ms 18100 KB Output is correct
76 Correct 179 ms 17552 KB Output is correct
77 Correct 205 ms 18180 KB Output is correct
78 Correct 215 ms 18252 KB Output is correct
79 Correct 186 ms 16424 KB Output is correct
80 Correct 238 ms 17492 KB Output is correct
81 Correct 238 ms 18436 KB Output is correct
82 Correct 266 ms 18388 KB Output is correct
83 Correct 106 ms 15316 KB Output is correct
84 Correct 215 ms 17056 KB Output is correct
85 Correct 83 ms 16460 KB Output is correct
86 Correct 123 ms 15372 KB Output is correct
87 Correct 192 ms 15080 KB Output is correct
88 Correct 252 ms 16044 KB Output is correct
89 Correct 168 ms 15268 KB Output is correct
90 Correct 184 ms 16332 KB Output is correct
91 Correct 153 ms 14156 KB Output is correct
92 Correct 196 ms 15700 KB Output is correct
93 Correct 226 ms 16208 KB Output is correct
94 Correct 143 ms 18460 KB Output is correct
95 Correct 184 ms 18996 KB Output is correct
96 Correct 120 ms 18948 KB Output is correct
97 Correct 153 ms 18580 KB Output is correct
98 Correct 175 ms 18676 KB Output is correct
99 Correct 205 ms 17988 KB Output is correct
100 Correct 224 ms 19188 KB Output is correct
101 Correct 179 ms 18260 KB Output is correct
102 Correct 213 ms 19096 KB Output is correct
103 Correct 254 ms 19016 KB Output is correct
104 Correct 193 ms 17680 KB Output is correct
105 Correct 238 ms 18872 KB Output is correct
106 Correct 272 ms 19016 KB Output is correct
107 Correct 99 ms 19232 KB Output is correct
108 Correct 139 ms 18192 KB Output is correct
109 Correct 139 ms 18264 KB Output is correct
110 Correct 139 ms 18472 KB Output is correct
111 Correct 140 ms 18208 KB Output is correct
112 Correct 137 ms 18220 KB Output is correct
113 Correct 147 ms 18220 KB Output is correct
114 Correct 139 ms 18220 KB Output is correct
115 Correct 137 ms 18216 KB Output is correct
116 Correct 136 ms 18196 KB Output is correct