답안 #1010966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010966 2024-06-29T15:27:39 Z VMaksimoski008 Joker (BOI20_joker) C++17
14 / 100
2000 ms 143136 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,bmi,bmi2,lzcnt,popcnt")

using pii = pair<int, int>;

struct DSU {
    int n;
    vector<pii> par;
    vector<int> size, bi;
 
    void init(int _n) {
        n = _n + 1;
        par.resize(n+1);
        size.resize(n+1, 1);
        bi.resize(n+1, 1);
        for(int i=1; i<=n; i++) par[i] = { i, 0 };
    }
 
    pii find(int u) {
        if(u == par[u].first) return par[u];
        int p = par[u].second;
        par[u] = find(par[u].first);
        par[u].second ^= p;
        return par[u];
    }
 
    bool uni(int a, int b) {
        pii pa = find(a), pb = find(b);
 
        if(pa.first == pb.first) {
            if(pa.second == pb.second) bi[pa.first] = 0;
            return 0;
        }
 
        if(size[pa.first] < size[pb.first]) swap(pa, pb);
        size[pa.first] += size[pb.first];
        par[pb.first] = { pa.first, pa.second ^ pb.second ^ 1 };
        bi[pa.first] &= bi[pb.first];
 
        return 1;
    }
 
    int getBi(int u) { return bi[find(u).first]; }
};

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

    int n, m, q;
    cin >> n >> m >> q;

    vector<array<int, 2> > edges(m+1);
    for(int i=1; i<=m; i++) cin >> edges[i][0] >> edges[i][1];

    vector<int> L(m+1), R(m+1, m), ANS(m+1, m+1);
    for(int i=1; i<=m; i++) L[i] = i;

    bool changed = 1;
    while(changed) {
        changed = 0;

        stack<int> to_change[m+1];
        for(int i=m; i>=1; i--)
            if(L[i] <= R[i]) to_change[(L[i] + R[i]) / 2].push(i);

        for(int i=1; i<=m; i++) {
            if(to_change[i].empty()) continue;
            changed = 1;

            DSU dsu; dsu.init(n);
            int ok = 1;
            for(int j=i+1; j<=m; j++) {
                dsu.uni(edges[j][0], edges[j][1]);
                // cout << edges[j][0] << " - " << edges[j][1] << '\n';
                if(!dsu.getBi(edges[j][0])) ok = 0;
            }

            // cout << i << ": " << ok << '\n';

            for(int j=1; j<=i; j++) {
                if(!to_change[i].empty() && to_change[i].top() == j) {
                    // cerr << i << " " << j << '\n';
                    if(ok) ANS[j] = i, R[j] = i - 1;
                    else L[j] = i + 1;
                    to_change[i].pop();
                }

                dsu.uni(edges[j][0], edges[j][1]);
                if(!dsu.getBi(edges[j][0])) ok = 0;
            }
        }
    }

    // for(int i=1; i<=n; i++) cout << i << ": " << ANS[i] << '\n';

    while(q--) {
        int l, r;
        cin >> l >> r;
        cout << (r >= ANS[l] ? "NO" : "YES") << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 93 ms 992 KB Output is correct
30 Correct 74 ms 1628 KB Output is correct
31 Correct 73 ms 1880 KB Output is correct
32 Correct 56 ms 1876 KB Output is correct
33 Correct 47 ms 1872 KB Output is correct
34 Correct 65 ms 1880 KB Output is correct
35 Correct 94 ms 1884 KB Output is correct
36 Correct 130 ms 1740 KB Output is correct
37 Correct 193 ms 1880 KB Output is correct
38 Correct 389 ms 1884 KB Output is correct
39 Correct 49 ms 1880 KB Output is correct
40 Correct 46 ms 1884 KB Output is correct
41 Correct 52 ms 1884 KB Output is correct
42 Correct 53 ms 1872 KB Output is correct
43 Correct 53 ms 1628 KB Output is correct
44 Correct 60 ms 1864 KB Output is correct
45 Correct 61 ms 1876 KB Output is correct
46 Correct 96 ms 1884 KB Output is correct
47 Correct 53 ms 1884 KB Output is correct
48 Correct 69 ms 1868 KB Output is correct
49 Correct 68 ms 1876 KB Output is correct
50 Correct 85 ms 1884 KB Output is correct
51 Correct 49 ms 1636 KB Output is correct
52 Correct 61 ms 1884 KB Output is correct
53 Correct 78 ms 1884 KB Output is correct
54 Correct 94 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2083 ms 143136 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Execution timed out 2083 ms 143136 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 93 ms 992 KB Output is correct
30 Correct 74 ms 1628 KB Output is correct
31 Correct 73 ms 1880 KB Output is correct
32 Correct 56 ms 1876 KB Output is correct
33 Correct 47 ms 1872 KB Output is correct
34 Correct 65 ms 1880 KB Output is correct
35 Correct 94 ms 1884 KB Output is correct
36 Correct 130 ms 1740 KB Output is correct
37 Correct 193 ms 1880 KB Output is correct
38 Correct 389 ms 1884 KB Output is correct
39 Correct 49 ms 1880 KB Output is correct
40 Correct 46 ms 1884 KB Output is correct
41 Correct 52 ms 1884 KB Output is correct
42 Correct 53 ms 1872 KB Output is correct
43 Correct 53 ms 1628 KB Output is correct
44 Correct 60 ms 1864 KB Output is correct
45 Correct 61 ms 1876 KB Output is correct
46 Correct 96 ms 1884 KB Output is correct
47 Correct 53 ms 1884 KB Output is correct
48 Correct 69 ms 1868 KB Output is correct
49 Correct 68 ms 1876 KB Output is correct
50 Correct 85 ms 1884 KB Output is correct
51 Correct 49 ms 1636 KB Output is correct
52 Correct 61 ms 1884 KB Output is correct
53 Correct 78 ms 1884 KB Output is correct
54 Correct 94 ms 1884 KB Output is correct
55 Execution timed out 2069 ms 142900 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 93 ms 992 KB Output is correct
30 Correct 74 ms 1628 KB Output is correct
31 Correct 73 ms 1880 KB Output is correct
32 Correct 56 ms 1876 KB Output is correct
33 Correct 47 ms 1872 KB Output is correct
34 Correct 65 ms 1880 KB Output is correct
35 Correct 94 ms 1884 KB Output is correct
36 Correct 130 ms 1740 KB Output is correct
37 Correct 193 ms 1880 KB Output is correct
38 Correct 389 ms 1884 KB Output is correct
39 Correct 49 ms 1880 KB Output is correct
40 Correct 46 ms 1884 KB Output is correct
41 Correct 52 ms 1884 KB Output is correct
42 Correct 53 ms 1872 KB Output is correct
43 Correct 53 ms 1628 KB Output is correct
44 Correct 60 ms 1864 KB Output is correct
45 Correct 61 ms 1876 KB Output is correct
46 Correct 96 ms 1884 KB Output is correct
47 Correct 53 ms 1884 KB Output is correct
48 Correct 69 ms 1868 KB Output is correct
49 Correct 68 ms 1876 KB Output is correct
50 Correct 85 ms 1884 KB Output is correct
51 Correct 49 ms 1636 KB Output is correct
52 Correct 61 ms 1884 KB Output is correct
53 Correct 78 ms 1884 KB Output is correct
54 Correct 94 ms 1884 KB Output is correct
55 Execution timed out 2083 ms 143136 KB Time limit exceeded
56 Halted 0 ms 0 KB -