답안 #1013806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1013806 2024-07-04T06:13:25 Z Mr_Husanboy Joker (BOI20_joker) C++17
49 / 100
2000 ms 33724 KB
//#pragma GCC optimize("Ofast,O3")
//#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;



#ifdef LOCAL
#include "debugger.cpp"
#else
#define debug(...)
#endif
template<class T>
int len(T &a){
    return a.size();
}

using ll = long long;
using pii = pair<int,int>;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
string fileio = "";

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll infl = 1e18;
const int maxn = 1e5 + 1;



struct DSU_roll_back{
    int n;
    vector<int> p;
    vector<int> sz;
    vector<int> d;
    vector<pair<int &, int>> his;
    int bip = 1;

    DSU_roll_back (int n) : n(n), p(n), sz(n), d(n){
        for(int i = 0; i < n;i ++) p[i] = i, sz[i] = 1;
    }

    int get(int x, int &col){
        col ^= d[x];
        return p[x] == x ? x : get(p[x], col);
    }

    void unite(int a, int b){
        if(bip == 0){
            return;
        }
        int ca = 0, cb = 0;
        a = get(a, ca), b = get(b, cb);
        if(a == b){
            if(ca == cb){
                his.push_back({bip, bip});
                bip = 0;
            }
            return;
        }
        if(sz[a] < sz[b]) swap(a, b);
        his.push_back({sz[a], sz[a]});
        his.push_back({p[b], p[b]});
        his.push_back({d[b], d[b]});
        d[b] = ca == cb;
        sz[a] += sz[b];
        p[b] = a;
    }

    int snap(){
        return his.size();
    }

    void roll_back(int until){
        while(len(his) > until){
            his.back().ff = his.back().ss;
            his.pop_back();
        }
    }
};

void solve(){
    int n, m, q; cin >> n >> m >> q;

    vector<int> a(m + 1), b(m + 1);

    for(int i = 1; i <= m; i ++){
        cin >> a[i] >> b[i]; a[i] --; b[i] --;
    }
    vector<vector<pair<int,int>>> qu(m + 1);
    for(int i = 0; i < q; i++){
        int l, r; cin >> l >> r;
        qu[l].push_back({r, i});
    }

    DSU_roll_back ds(n);
    vector<int> ans(q);

    for(int i = 1; i <= m; i ++){
        if(len(qu[i])){
            int sz = ds.snap();
            int r = m;
            while(ds.bip && r >= i){
                ds.unite(a[r], b[r]);
                r --;
            }

            for(auto [rig, j] : qu[i]){
                ans[j] = rig <= r;
            }
            debug(i, r);
            ds.roll_back(sz);
        }
        ds.unite(a[i], b[i]);
    }
    for(auto u : ans) cout << (u ? "YES" : "NO") << '\n';
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    auto start = chrono::high_resolution_clock::now();
    #ifndef LOCAL
    if(fileio.size()){
        freopen((fileio + ".in").c_str(), "r", stdin);
        freopen((fileio + ".out").c_str(), "w", stdout);
    }
    #endif
    int testcases = 1;
    #ifdef Tests
    cin >> testcases;
    #endif
    while(testcases --){
        solve();
        if(testcases) cout << '\n';
        #ifdef LOCAL
        else cout << '\n';
        cout << "_________________________" << endl;
        #endif
    }
    #ifdef LOCAL
    auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
    
    cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
    #endif
    return 0;
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:123:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
  123 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
Joker.cpp:126:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  126 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:127:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  127 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 604 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 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 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 604 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 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 11 ms 696 KB Output is correct
30 Correct 9 ms 604 KB Output is correct
31 Correct 7 ms 604 KB Output is correct
32 Correct 4 ms 604 KB Output is correct
33 Correct 1 ms 632 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 11 ms 744 KB Output is correct
36 Correct 9 ms 560 KB Output is correct
37 Correct 22 ms 864 KB Output is correct
38 Correct 30 ms 600 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 2 ms 472 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 4 ms 748 KB Output is correct
46 Correct 10 ms 752 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 5 ms 856 KB Output is correct
49 Correct 5 ms 744 KB Output is correct
50 Correct 9 ms 760 KB Output is correct
51 Correct 2 ms 600 KB Output is correct
52 Correct 3 ms 556 KB Output is correct
53 Correct 5 ms 604 KB Output is correct
54 Correct 10 ms 604 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 51 ms 23628 KB Output is correct
4 Correct 68 ms 31560 KB Output is correct
5 Correct 59 ms 33348 KB Output is correct
6 Correct 57 ms 23872 KB Output is correct
7 Correct 61 ms 24136 KB Output is correct
8 Correct 49 ms 18548 KB Output is correct
9 Correct 53 ms 18420 KB Output is correct
10 Correct 58 ms 24908 KB Output is correct
11 Correct 60 ms 20044 KB Output is correct
12 Correct 57 ms 24904 KB Output is correct
13 Correct 48 ms 15560 KB Output is correct
14 Correct 52 ms 19020 KB Output is correct
15 Correct 58 ms 24900 KB Output is correct
16 Correct 67 ms 25928 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 604 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 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 51 ms 23628 KB Output is correct
30 Correct 68 ms 31560 KB Output is correct
31 Correct 59 ms 33348 KB Output is correct
32 Correct 57 ms 23872 KB Output is correct
33 Correct 61 ms 24136 KB Output is correct
34 Correct 49 ms 18548 KB Output is correct
35 Correct 53 ms 18420 KB Output is correct
36 Correct 58 ms 24908 KB Output is correct
37 Correct 60 ms 20044 KB Output is correct
38 Correct 57 ms 24904 KB Output is correct
39 Correct 48 ms 15560 KB Output is correct
40 Correct 52 ms 19020 KB Output is correct
41 Correct 58 ms 24900 KB Output is correct
42 Correct 67 ms 25928 KB Output is correct
43 Correct 570 ms 23764 KB Output is correct
44 Correct 1288 ms 33724 KB Output is correct
45 Correct 1236 ms 32872 KB Output is correct
46 Correct 87 ms 23740 KB Output is correct
47 Correct 102 ms 23520 KB Output is correct
48 Correct 455 ms 20680 KB Output is correct
49 Correct 835 ms 24548 KB Output is correct
50 Correct 639 ms 20928 KB Output is correct
51 Correct 659 ms 24256 KB Output is correct
52 Correct 651 ms 26100 KB Output is correct
53 Correct 392 ms 15560 KB Output is correct
54 Correct 407 ms 20928 KB Output is correct
55 Correct 635 ms 25152 KB Output is correct
56 Correct 778 ms 26344 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 604 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 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 11 ms 696 KB Output is correct
30 Correct 9 ms 604 KB Output is correct
31 Correct 7 ms 604 KB Output is correct
32 Correct 4 ms 604 KB Output is correct
33 Correct 1 ms 632 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 11 ms 744 KB Output is correct
36 Correct 9 ms 560 KB Output is correct
37 Correct 22 ms 864 KB Output is correct
38 Correct 30 ms 600 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 2 ms 472 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 4 ms 748 KB Output is correct
46 Correct 10 ms 752 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 5 ms 856 KB Output is correct
49 Correct 5 ms 744 KB Output is correct
50 Correct 9 ms 760 KB Output is correct
51 Correct 2 ms 600 KB Output is correct
52 Correct 3 ms 556 KB Output is correct
53 Correct 5 ms 604 KB Output is correct
54 Correct 10 ms 604 KB Output is correct
55 Correct 1335 ms 18880 KB Output is correct
56 Execution timed out 2032 ms 28856 KB Time limit exceeded
57 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 604 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 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 11 ms 696 KB Output is correct
30 Correct 9 ms 604 KB Output is correct
31 Correct 7 ms 604 KB Output is correct
32 Correct 4 ms 604 KB Output is correct
33 Correct 1 ms 632 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 11 ms 744 KB Output is correct
36 Correct 9 ms 560 KB Output is correct
37 Correct 22 ms 864 KB Output is correct
38 Correct 30 ms 600 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 2 ms 472 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 4 ms 748 KB Output is correct
46 Correct 10 ms 752 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 5 ms 856 KB Output is correct
49 Correct 5 ms 744 KB Output is correct
50 Correct 9 ms 760 KB Output is correct
51 Correct 2 ms 600 KB Output is correct
52 Correct 3 ms 556 KB Output is correct
53 Correct 5 ms 604 KB Output is correct
54 Correct 10 ms 604 KB Output is correct
55 Correct 51 ms 23628 KB Output is correct
56 Correct 68 ms 31560 KB Output is correct
57 Correct 59 ms 33348 KB Output is correct
58 Correct 57 ms 23872 KB Output is correct
59 Correct 61 ms 24136 KB Output is correct
60 Correct 49 ms 18548 KB Output is correct
61 Correct 53 ms 18420 KB Output is correct
62 Correct 58 ms 24908 KB Output is correct
63 Correct 60 ms 20044 KB Output is correct
64 Correct 57 ms 24904 KB Output is correct
65 Correct 48 ms 15560 KB Output is correct
66 Correct 52 ms 19020 KB Output is correct
67 Correct 58 ms 24900 KB Output is correct
68 Correct 67 ms 25928 KB Output is correct
69 Correct 570 ms 23764 KB Output is correct
70 Correct 1288 ms 33724 KB Output is correct
71 Correct 1236 ms 32872 KB Output is correct
72 Correct 87 ms 23740 KB Output is correct
73 Correct 102 ms 23520 KB Output is correct
74 Correct 455 ms 20680 KB Output is correct
75 Correct 835 ms 24548 KB Output is correct
76 Correct 639 ms 20928 KB Output is correct
77 Correct 659 ms 24256 KB Output is correct
78 Correct 651 ms 26100 KB Output is correct
79 Correct 392 ms 15560 KB Output is correct
80 Correct 407 ms 20928 KB Output is correct
81 Correct 635 ms 25152 KB Output is correct
82 Correct 778 ms 26344 KB Output is correct
83 Correct 1335 ms 18880 KB Output is correct
84 Execution timed out 2032 ms 28856 KB Time limit exceeded
85 Halted 0 ms 0 KB -