Submission #973348

# Submission time Handle Problem Language Result Execution time Memory
973348 2024-05-01T19:22:57 Z vladilius Joker (BOI20_joker) C++17
14 / 100
2000 ms 21936 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

struct dsu{
    vector<pair<int&, int>> hist;
    vector<int> sz, p;
    vector<bool> f;
    int n, S, Sf;
    dsu(int ns){
        n = ns;
        p.resize(2 * n + 1);
        sz.resize(2 * n + 1);
        for (int i = 1; i <= 2 * n; i++){
            p[i] = i;
            sz[i] = 1;
        }
    }
    void save(){
        S = (int) hist.size();
        Sf = (int) f.size();
    }
    int get(int v){
        if (p[v] != v){
            return get(p[v]);
        }
        return v;
    }
    int op(int v){
        return v + n;
    }
    void roll_back(){
        while (hist.size() != S){
            hist.back().ff = hist.back().ss;
            hist.pop_back();
        }
        while (f.size() != Sf){
            f.pop_back();
        }
    }
    void unite(int x, int y){
        x = get(x); y = get(y);
        if (x == y) return;
        if (sz[x] > sz[y]) swap(x, y);
        hist.pb({p[x], p[x]});
        hist.pb({sz[y], sz[y]});
        p[x] = y;
        sz[y] += sz[x];
    }
    bool add(pii P){
        auto [x, y] = P;
        if (!x) return 0;
        unite(x, op(y));
        unite(y, op(x));
        bool k = ((!f.empty() && f.back()) | (get(x) == get(y)));
        f.pb(k);
        return k;
    }
};

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

    int n, M, q; cin>>n>>M>>q;
    vector<pii> ed = {{0, 0}};
    for (int i = 1; i <= M; i++){
        int u, v; cin>>u>>v;
        ed.pb({u, v});
    }
    /*
    dsu T(n);
    T.save();
    for (int i = 1; i <= M; i++){
        T.add(ed[i]);
    }
    if (!T.f.back()){
        for (int i = 1; i <= q; i++){
            cout<<"NO"<<"\n";
        }
        return 0;
    }
    T.roll_back();
    
    vector<int> last(M + 1);
    function<void(int, int, pii)> solve = [&](int l, int r, pii R){
        if (l > r) return;

        int m = (l + r) / 2;
        T.save();
        for (int i = l; i < m; i++){
            T.add(ed[i]);
        }
        int i = R.ss;
        while (T.f.empty() || !T.f.back()){
            T.add(ed[i--]);
        }
        last[m] = i;
        T.roll_back();
        
        T.save();
        for (int i = last[m] + 1; i <= R.ss; i++){
            T.add(ed[i]);
        }
        solve(l, m - 1, {R.ff, last[m]});
        T.roll_back();
        
        T.save();
        for (int i = l; i <= m; i++){
            T.add(ed[i]);
        }
        solve(m + 1, r, {last[m], R.ss});
        T.roll_back();
    };
    
    solve(1, M, {0, M});
     */
    vector<int> last(M + 1);
    for (int i = 1; i <= M; i++){
        dsu T(n);
        for (int j = 1; j < i; j++){
            T.add(ed[j]);
        }
        if (!T.f.empty() && T.f.back()){
            last[i] = M;
            continue;
        }
        for (int j = M; j > 0; j--){
            if (T.add(ed[j])){
                // [1, i - 1] U [j, M] = [1, M] \ [i, j - 1]
                last[i] = j - 1;
                break;
            }
        }
    }

    while (q--){
        int l, r; cin>>l>>r;
        cout<<((r <= last[l]) ? "YES" : "NO")<<"\n";
    }
}

Compilation message

Joker.cpp: In member function 'void dsu::roll_back()':
Joker.cpp:37:28: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int&, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |         while (hist.size() != S){
      |                ~~~~~~~~~~~~^~~~
Joker.cpp:41:25: warning: comparison of integer expressions of different signedness: 'std::vector<bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |         while (f.size() != Sf){
      |                ~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 496 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 500 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 360 KB Output is correct
16 Correct 2 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 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 496 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 500 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 360 KB Output is correct
16 Correct 2 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 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 480 KB Output is correct
29 Correct 64 ms 648 KB Output is correct
30 Correct 147 ms 748 KB Output is correct
31 Correct 138 ms 728 KB Output is correct
32 Correct 100 ms 876 KB Output is correct
33 Correct 86 ms 624 KB Output is correct
34 Correct 149 ms 756 KB Output is correct
35 Correct 181 ms 752 KB Output is correct
36 Correct 107 ms 936 KB Output is correct
37 Correct 218 ms 812 KB Output is correct
38 Correct 277 ms 812 KB Output is correct
39 Correct 134 ms 756 KB Output is correct
40 Correct 99 ms 648 KB Output is correct
41 Correct 91 ms 656 KB Output is correct
42 Correct 88 ms 656 KB Output is correct
43 Correct 89 ms 628 KB Output is correct
44 Correct 118 ms 648 KB Output is correct
45 Correct 133 ms 732 KB Output is correct
46 Correct 171 ms 760 KB Output is correct
47 Correct 81 ms 768 KB Output is correct
48 Correct 94 ms 656 KB Output is correct
49 Correct 124 ms 724 KB Output is correct
50 Correct 163 ms 2864 KB Output is correct
51 Correct 90 ms 632 KB Output is correct
52 Correct 100 ms 644 KB Output is correct
53 Correct 129 ms 724 KB Output is correct
54 Correct 173 ms 756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2025 ms 21344 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 496 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 500 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 360 KB Output is correct
16 Correct 2 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 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 480 KB Output is correct
29 Execution timed out 2025 ms 21344 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 496 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 500 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 360 KB Output is correct
16 Correct 2 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 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 480 KB Output is correct
29 Correct 64 ms 648 KB Output is correct
30 Correct 147 ms 748 KB Output is correct
31 Correct 138 ms 728 KB Output is correct
32 Correct 100 ms 876 KB Output is correct
33 Correct 86 ms 624 KB Output is correct
34 Correct 149 ms 756 KB Output is correct
35 Correct 181 ms 752 KB Output is correct
36 Correct 107 ms 936 KB Output is correct
37 Correct 218 ms 812 KB Output is correct
38 Correct 277 ms 812 KB Output is correct
39 Correct 134 ms 756 KB Output is correct
40 Correct 99 ms 648 KB Output is correct
41 Correct 91 ms 656 KB Output is correct
42 Correct 88 ms 656 KB Output is correct
43 Correct 89 ms 628 KB Output is correct
44 Correct 118 ms 648 KB Output is correct
45 Correct 133 ms 732 KB Output is correct
46 Correct 171 ms 760 KB Output is correct
47 Correct 81 ms 768 KB Output is correct
48 Correct 94 ms 656 KB Output is correct
49 Correct 124 ms 724 KB Output is correct
50 Correct 163 ms 2864 KB Output is correct
51 Correct 90 ms 632 KB Output is correct
52 Correct 100 ms 644 KB Output is correct
53 Correct 129 ms 724 KB Output is correct
54 Correct 173 ms 756 KB Output is correct
55 Execution timed out 2035 ms 21936 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 496 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 500 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 360 KB Output is correct
16 Correct 2 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 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 480 KB Output is correct
29 Correct 64 ms 648 KB Output is correct
30 Correct 147 ms 748 KB Output is correct
31 Correct 138 ms 728 KB Output is correct
32 Correct 100 ms 876 KB Output is correct
33 Correct 86 ms 624 KB Output is correct
34 Correct 149 ms 756 KB Output is correct
35 Correct 181 ms 752 KB Output is correct
36 Correct 107 ms 936 KB Output is correct
37 Correct 218 ms 812 KB Output is correct
38 Correct 277 ms 812 KB Output is correct
39 Correct 134 ms 756 KB Output is correct
40 Correct 99 ms 648 KB Output is correct
41 Correct 91 ms 656 KB Output is correct
42 Correct 88 ms 656 KB Output is correct
43 Correct 89 ms 628 KB Output is correct
44 Correct 118 ms 648 KB Output is correct
45 Correct 133 ms 732 KB Output is correct
46 Correct 171 ms 760 KB Output is correct
47 Correct 81 ms 768 KB Output is correct
48 Correct 94 ms 656 KB Output is correct
49 Correct 124 ms 724 KB Output is correct
50 Correct 163 ms 2864 KB Output is correct
51 Correct 90 ms 632 KB Output is correct
52 Correct 100 ms 644 KB Output is correct
53 Correct 129 ms 724 KB Output is correct
54 Correct 173 ms 756 KB Output is correct
55 Execution timed out 2025 ms 21344 KB Time limit exceeded
56 Halted 0 ms 0 KB -