답안 #1010969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010969 2024-06-29T15:29:42 Z VMaksimoski008 Joker (BOI20_joker) C++17
14 / 100
2000 ms 142936 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&&ok; 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&&ok; 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;
            }

            while(!to_change[i].empty()) {
                int u = to_change[i].top();
                to_change[i].pop();
                L[u] = i + 1;
            }
        }
    }

    // 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 348 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 352 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 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 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 600 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 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 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 600 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 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 348 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 352 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 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 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 600 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 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 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 600 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 75 ms 1116 KB Output is correct
30 Correct 53 ms 1628 KB Output is correct
31 Correct 31 ms 1880 KB Output is correct
32 Correct 18 ms 1884 KB Output is correct
33 Correct 9 ms 1884 KB Output is correct
34 Correct 27 ms 1880 KB Output is correct
35 Correct 47 ms 1884 KB Output is correct
36 Correct 59 ms 1884 KB Output is correct
37 Correct 173 ms 1880 KB Output is correct
38 Correct 385 ms 1884 KB Output is correct
39 Correct 18 ms 1884 KB Output is correct
40 Correct 14 ms 1880 KB Output is correct
41 Correct 13 ms 1884 KB Output is correct
42 Correct 13 ms 1884 KB Output is correct
43 Correct 14 ms 1884 KB Output is correct
44 Correct 19 ms 1888 KB Output is correct
45 Correct 22 ms 1884 KB Output is correct
46 Correct 42 ms 1880 KB Output is correct
47 Correct 27 ms 1880 KB Output is correct
48 Correct 30 ms 1892 KB Output is correct
49 Correct 31 ms 1880 KB Output is correct
50 Correct 42 ms 1880 KB Output is correct
51 Correct 15 ms 1884 KB Output is correct
52 Correct 18 ms 1888 KB Output is correct
53 Correct 25 ms 1884 KB Output is correct
54 Correct 44 ms 1880 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 2074 ms 142936 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 348 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 352 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 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 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 600 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 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 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 600 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Execution timed out 2074 ms 142936 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 348 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 352 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 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 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 600 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 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 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 600 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 75 ms 1116 KB Output is correct
30 Correct 53 ms 1628 KB Output is correct
31 Correct 31 ms 1880 KB Output is correct
32 Correct 18 ms 1884 KB Output is correct
33 Correct 9 ms 1884 KB Output is correct
34 Correct 27 ms 1880 KB Output is correct
35 Correct 47 ms 1884 KB Output is correct
36 Correct 59 ms 1884 KB Output is correct
37 Correct 173 ms 1880 KB Output is correct
38 Correct 385 ms 1884 KB Output is correct
39 Correct 18 ms 1884 KB Output is correct
40 Correct 14 ms 1880 KB Output is correct
41 Correct 13 ms 1884 KB Output is correct
42 Correct 13 ms 1884 KB Output is correct
43 Correct 14 ms 1884 KB Output is correct
44 Correct 19 ms 1888 KB Output is correct
45 Correct 22 ms 1884 KB Output is correct
46 Correct 42 ms 1880 KB Output is correct
47 Correct 27 ms 1880 KB Output is correct
48 Correct 30 ms 1892 KB Output is correct
49 Correct 31 ms 1880 KB Output is correct
50 Correct 42 ms 1880 KB Output is correct
51 Correct 15 ms 1884 KB Output is correct
52 Correct 18 ms 1888 KB Output is correct
53 Correct 25 ms 1884 KB Output is correct
54 Correct 44 ms 1880 KB Output is correct
55 Execution timed out 2033 ms 142928 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 348 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 352 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 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 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 600 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 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 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 600 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 75 ms 1116 KB Output is correct
30 Correct 53 ms 1628 KB Output is correct
31 Correct 31 ms 1880 KB Output is correct
32 Correct 18 ms 1884 KB Output is correct
33 Correct 9 ms 1884 KB Output is correct
34 Correct 27 ms 1880 KB Output is correct
35 Correct 47 ms 1884 KB Output is correct
36 Correct 59 ms 1884 KB Output is correct
37 Correct 173 ms 1880 KB Output is correct
38 Correct 385 ms 1884 KB Output is correct
39 Correct 18 ms 1884 KB Output is correct
40 Correct 14 ms 1880 KB Output is correct
41 Correct 13 ms 1884 KB Output is correct
42 Correct 13 ms 1884 KB Output is correct
43 Correct 14 ms 1884 KB Output is correct
44 Correct 19 ms 1888 KB Output is correct
45 Correct 22 ms 1884 KB Output is correct
46 Correct 42 ms 1880 KB Output is correct
47 Correct 27 ms 1880 KB Output is correct
48 Correct 30 ms 1892 KB Output is correct
49 Correct 31 ms 1880 KB Output is correct
50 Correct 42 ms 1880 KB Output is correct
51 Correct 15 ms 1884 KB Output is correct
52 Correct 18 ms 1888 KB Output is correct
53 Correct 25 ms 1884 KB Output is correct
54 Correct 44 ms 1880 KB Output is correct
55 Execution timed out 2074 ms 142936 KB Time limit exceeded
56 Halted 0 ms 0 KB -