답안 #963731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963731 2024-04-15T14:40:15 Z Pring Joker (BOI20_joker) C++17
100 / 100
276 ms 18088 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MXN = 200005;
int n, m, q, x, y;
int eu[MXN], ev[MXN];
int l[MXN], L;

struct DSU {
    int p[MXN * 2];
    vector<pii> st;
    vector<bool> isb;
    void init(int n) {
        fill(p + 1, p + n * 2 + 1, -1);
        st.clear();
        isb.clear();
        isb.push_back(0);
    }
    int find(int x) {
        return (p[x] < 0 ? x : find(p[x]));
    }
    bool onion(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            st.push_back(mp(0, 0));
            st.push_back(mp(0, 0));
            return false;
        }
        if (p[x] > p[y]) swap(x, y);
        st.push_back(mp(x, p[x]));
        st.push_back(mp(y, p[y]));
        p[x] += p[y];
        p[y] = x;
        return true;
    }
    void undo() {
        p[st.back().fs] = st.back().sc;
        st.pop_back();
        p[st.back().fs] = st.back().sc;
        st.pop_back();
    }
    bool ONION(int x, int y) {
        onion(x, y + n);
        onion(x + n, y);
        bool f = (isb.back() | (find(x) == find(y)));
        isb.push_back(f);
        return f;
    }
    void BACK() {
        undo();
        undo();
        isb.pop_back();
    }
} dsu;

int ODD_CYCLE() {
    dsu.init(n);
    FOR(i, 0, m) if (dsu.ONION(eu[i], ev[i])) return i + 1;
    return -1;
}

void MOVE() {
    while (!dsu.isb.back()) {
        dsu.ONION(eu[L], ev[L]);
        L++;
    }
}

void MOVE(int x) {
    while (L < x) {
        dsu.ONION(eu[L], ev[L]);
        L++;
    }
    while (L > x) {
        dsu.BACK();
        L--;
    }
}

void calc(int sl, int sr) {
    if (sl == sr) return;
    int mid = (sl + sr) >> 1;
    for (int i = sr; i > mid; i--) dsu.ONION(eu[i - 1], ev[i - 1]);
    int pl = L;
    MOVE();
    l[mid] = L;
    MOVE(pl);
    calc(sl, mid);
    for (int i = sr; i > mid; i--) dsu.BACK();
    MOVE(l[mid]);
    calc(mid + 1, sr);
    MOVE(pl);
}

void miku() {
    cin >> n >> m >> q;
    FOR(i, 0, m) cin >> eu[i] >> ev[i];
    l[m] = ODD_CYCLE();
    if (l[m] == -1) {
        while (q--) cout << "NO" << '\n';
        return;
    }
    dsu.init(n);
    calc(0, m);
    // FOR(i, 0, m + 1) cout << l[i] << '\n';
    while (q--) {
        cin >> x >> y;
        cout << (x > l[y] ? "YES" : "NO") << '\n';
    }
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2740 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2520 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2524 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2516 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2740 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2520 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2524 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2516 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2648 KB Output is correct
30 Correct 2 ms 2648 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 4 ms 2580 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 1 ms 2648 KB Output is correct
39 Correct 2 ms 2652 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 2 ms 2532 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2496 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 2 ms 2652 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 2 ms 2652 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2652 KB Output is correct
52 Correct 2 ms 2648 KB Output is correct
53 Correct 3 ms 2648 KB Output is correct
54 Correct 2 ms 2532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2740 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 179 ms 14740 KB Output is correct
4 Correct 43 ms 16836 KB Output is correct
5 Correct 166 ms 16568 KB Output is correct
6 Correct 192 ms 15244 KB Output is correct
7 Correct 207 ms 16692 KB Output is correct
8 Correct 184 ms 16332 KB Output is correct
9 Correct 212 ms 16472 KB Output is correct
10 Correct 256 ms 16580 KB Output is correct
11 Correct 197 ms 16916 KB Output is correct
12 Correct 210 ms 15668 KB Output is correct
13 Correct 150 ms 16212 KB Output is correct
14 Correct 196 ms 15428 KB Output is correct
15 Correct 224 ms 16760 KB Output is correct
16 Correct 259 ms 16256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2740 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2520 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2524 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2516 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 179 ms 14740 KB Output is correct
30 Correct 43 ms 16836 KB Output is correct
31 Correct 166 ms 16568 KB Output is correct
32 Correct 192 ms 15244 KB Output is correct
33 Correct 207 ms 16692 KB Output is correct
34 Correct 184 ms 16332 KB Output is correct
35 Correct 212 ms 16472 KB Output is correct
36 Correct 256 ms 16580 KB Output is correct
37 Correct 197 ms 16916 KB Output is correct
38 Correct 210 ms 15668 KB Output is correct
39 Correct 150 ms 16212 KB Output is correct
40 Correct 196 ms 15428 KB Output is correct
41 Correct 224 ms 16760 KB Output is correct
42 Correct 259 ms 16256 KB Output is correct
43 Correct 194 ms 16876 KB Output is correct
44 Correct 43 ms 16836 KB Output is correct
45 Correct 172 ms 16432 KB Output is correct
46 Correct 177 ms 17084 KB Output is correct
47 Correct 210 ms 16956 KB Output is correct
48 Correct 225 ms 16924 KB Output is correct
49 Correct 250 ms 15612 KB Output is correct
50 Correct 179 ms 15960 KB Output is correct
51 Correct 196 ms 16564 KB Output is correct
52 Correct 209 ms 16272 KB Output is correct
53 Correct 153 ms 15556 KB Output is correct
54 Correct 230 ms 15632 KB Output is correct
55 Correct 226 ms 15772 KB Output is correct
56 Correct 241 ms 16516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2740 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2520 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2524 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2516 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2648 KB Output is correct
30 Correct 2 ms 2648 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 4 ms 2580 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 1 ms 2648 KB Output is correct
39 Correct 2 ms 2652 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 2 ms 2532 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2496 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 2 ms 2652 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 2 ms 2652 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2652 KB Output is correct
52 Correct 2 ms 2648 KB Output is correct
53 Correct 3 ms 2648 KB Output is correct
54 Correct 2 ms 2532 KB Output is correct
55 Correct 152 ms 15812 KB Output is correct
56 Correct 38 ms 16580 KB Output is correct
57 Correct 133 ms 16092 KB Output is correct
58 Correct 161 ms 15632 KB Output is correct
59 Correct 190 ms 16076 KB Output is correct
60 Correct 211 ms 15816 KB Output is correct
61 Correct 161 ms 15048 KB Output is correct
62 Correct 178 ms 15816 KB Output is correct
63 Correct 143 ms 16396 KB Output is correct
64 Correct 191 ms 15004 KB Output is correct
65 Correct 207 ms 16452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2740 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2520 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2524 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2516 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2648 KB Output is correct
30 Correct 2 ms 2648 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 4 ms 2580 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 1 ms 2648 KB Output is correct
39 Correct 2 ms 2652 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 2 ms 2532 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2496 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 2 ms 2652 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 2 ms 2652 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2652 KB Output is correct
52 Correct 2 ms 2648 KB Output is correct
53 Correct 3 ms 2648 KB Output is correct
54 Correct 2 ms 2532 KB Output is correct
55 Correct 179 ms 14740 KB Output is correct
56 Correct 43 ms 16836 KB Output is correct
57 Correct 166 ms 16568 KB Output is correct
58 Correct 192 ms 15244 KB Output is correct
59 Correct 207 ms 16692 KB Output is correct
60 Correct 184 ms 16332 KB Output is correct
61 Correct 212 ms 16472 KB Output is correct
62 Correct 256 ms 16580 KB Output is correct
63 Correct 197 ms 16916 KB Output is correct
64 Correct 210 ms 15668 KB Output is correct
65 Correct 150 ms 16212 KB Output is correct
66 Correct 196 ms 15428 KB Output is correct
67 Correct 224 ms 16760 KB Output is correct
68 Correct 259 ms 16256 KB Output is correct
69 Correct 194 ms 16876 KB Output is correct
70 Correct 43 ms 16836 KB Output is correct
71 Correct 172 ms 16432 KB Output is correct
72 Correct 177 ms 17084 KB Output is correct
73 Correct 210 ms 16956 KB Output is correct
74 Correct 225 ms 16924 KB Output is correct
75 Correct 250 ms 15612 KB Output is correct
76 Correct 179 ms 15960 KB Output is correct
77 Correct 196 ms 16564 KB Output is correct
78 Correct 209 ms 16272 KB Output is correct
79 Correct 153 ms 15556 KB Output is correct
80 Correct 230 ms 15632 KB Output is correct
81 Correct 226 ms 15772 KB Output is correct
82 Correct 241 ms 16516 KB Output is correct
83 Correct 152 ms 15812 KB Output is correct
84 Correct 38 ms 16580 KB Output is correct
85 Correct 133 ms 16092 KB Output is correct
86 Correct 161 ms 15632 KB Output is correct
87 Correct 190 ms 16076 KB Output is correct
88 Correct 211 ms 15816 KB Output is correct
89 Correct 161 ms 15048 KB Output is correct
90 Correct 178 ms 15816 KB Output is correct
91 Correct 143 ms 16396 KB Output is correct
92 Correct 191 ms 15004 KB Output is correct
93 Correct 207 ms 16452 KB Output is correct
94 Correct 184 ms 17288 KB Output is correct
95 Correct 247 ms 16736 KB Output is correct
96 Correct 169 ms 16688 KB Output is correct
97 Correct 181 ms 17748 KB Output is correct
98 Correct 219 ms 16400 KB Output is correct
99 Correct 187 ms 17072 KB Output is correct
100 Correct 232 ms 18024 KB Output is correct
101 Correct 193 ms 17780 KB Output is correct
102 Correct 206 ms 17076 KB Output is correct
103 Correct 219 ms 17592 KB Output is correct
104 Correct 199 ms 17264 KB Output is correct
105 Correct 249 ms 16440 KB Output is correct
106 Correct 276 ms 18088 KB Output is correct
107 Correct 136 ms 17732 KB Output is correct
108 Correct 194 ms 16692 KB Output is correct
109 Correct 194 ms 17068 KB Output is correct
110 Correct 189 ms 17820 KB Output is correct
111 Correct 208 ms 16288 KB Output is correct
112 Correct 188 ms 17072 KB Output is correct
113 Correct 191 ms 17844 KB Output is correct
114 Correct 191 ms 17708 KB Output is correct
115 Correct 187 ms 16200 KB Output is correct
116 Correct 185 ms 17720 KB Output is correct