Submission #1045706

# Submission time Handle Problem Language Result Execution time Memory
1045706 2024-08-06T07:03:34 Z hirayuu_oj Joker (BOI20_joker) C++17
49 / 100
2000 ms 25340 KB
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rng(i,l,r) for(int i=(l); i<(r); i++)
#define all(x) x.begin(),x.end()
using ll=long long;

struct odd_cycle {
    int size;
    vector<int> uni;
    int time;
    stack<array<int,4>> memo;
    bool isok;
    odd_cycle(int sz) {
        size=sz;
        time=0;
        isok=false;
        memo.push({-1,-1,0,-1});
        uni.resize(size*2,-1);
    }
    int leader(int p) {
        while(uni[p]>=0)p=uni[p];
        return p;
    }
    void merge(pair<int,int> x) {
        if(isok) {
            time++;
            return;
        }
        int u=x.first;
        int v=x.second;
        int a=leader(u),d=leader(v+size);
        if(-uni[a]>-uni[d])swap(a,d);
        if(a!=d) {
            memo.push({a,uni[a],isok,time});
            memo.push({d,uni[d],isok,time});
            uni[d]+=uni[a];
            uni[a]=d;
        }
        int b=leader(v),c=leader(u+size);
        if(-uni[b]>-uni[c])swap(b,c);
        if(b!=c) {
            memo.push({b,uni[b],isok,time});
            memo.push({c,uni[c],isok,time});
            uni[c]+=uni[b];
            uni[b]=c;
        }
        if(leader(u)==leader(u+size))isok=true;
        time++;
    }
    void undo() {
        time--;
        while(memo.top()[3]==time) {
            isok=memo.top()[2];
            uni[memo.top()[0]]=memo.top()[1];
            memo.pop();
        }
    }

};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M,Q;
    cin>>N>>M>>Q;
    const int backet=250;
    vector<pair<int,int>> edge(M);
    rep(i,M) {
        int u,v;
        cin>>u>>v;
        edge[i]={u-1,v-1};
    }
    vector<vector<array<int,3>>> query(3+M/backet);
    rep(i,Q) {
        int l,r;
        cin>>l>>r;
        query[(l-1)/backet].push_back({-r,l-1,i});
    }
    vector<string> ans(Q);
    rep(i,3+M/backet) {
        if(query[i].empty())continue;
        sort(all(query[i]));
        odd_cycle uni(N);
        rep(j,backet*i)uni.merge(edge[j]);
        int ri=M;
        rep(j,query[i].size()) {
            int r=-query[i][j][0];
            int l=query[i][j][1];
            int ind=query[i][j][2];
            rng(k,r,ri) {
                uni.merge(edge[k]);
            }
            ri=r;
            rep(k,l%backet) {
                uni.merge(edge[i*backet+k]);
            }
            if(uni.isok)ans[ind]="YES";
            else ans[ind]="NO";
            rep(k,l%backet) {
                uni.undo();
            }
        }
    }
    rep(i,Q) {
        cout<<ans[i]<<"\n";
    }
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:3:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define rep(i,n) for(int i=0; i<(n); i++)
      |                                ^
Joker.cpp:86:9: note: in expansion of macro 'rep'
   86 |         rep(j,query[i].size()) {
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 348 KB Output is correct
7 Correct 0 ms 348 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 1 ms 344 KB Output is correct
15 Correct 2 ms 344 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 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 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 420 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 348 KB Output is correct
7 Correct 0 ms 348 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 1 ms 344 KB Output is correct
15 Correct 2 ms 344 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 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 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 420 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 10 ms 604 KB Output is correct
30 Correct 6 ms 604 KB Output is correct
31 Correct 6 ms 604 KB Output is correct
32 Correct 4 ms 604 KB Output is correct
33 Correct 3 ms 608 KB Output is correct
34 Correct 6 ms 604 KB Output is correct
35 Correct 6 ms 604 KB Output is correct
36 Correct 5 ms 604 KB Output is correct
37 Correct 9 ms 604 KB Output is correct
38 Correct 11 ms 724 KB Output is correct
39 Correct 11 ms 640 KB Output is correct
40 Correct 5 ms 604 KB Output is correct
41 Correct 5 ms 604 KB Output is correct
42 Correct 5 ms 656 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 4 ms 600 KB Output is correct
46 Correct 4 ms 604 KB Output is correct
47 Correct 6 ms 604 KB Output is correct
48 Correct 5 ms 604 KB Output is correct
49 Correct 6 ms 656 KB Output is correct
50 Correct 5 ms 604 KB Output is correct
51 Correct 6 ms 604 KB Output is correct
52 Correct 5 ms 604 KB Output is correct
53 Correct 8 ms 604 KB Output is correct
54 Correct 6 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 64 ms 17944 KB Output is correct
4 Correct 85 ms 25284 KB Output is correct
5 Correct 61 ms 14020 KB Output is correct
6 Correct 71 ms 18312 KB Output is correct
7 Correct 76 ms 17756 KB Output is correct
8 Correct 64 ms 15400 KB Output is correct
9 Correct 64 ms 16920 KB Output is correct
10 Correct 102 ms 18620 KB Output is correct
11 Correct 86 ms 17348 KB Output is correct
12 Correct 75 ms 18524 KB Output is correct
13 Correct 62 ms 12736 KB Output is correct
14 Correct 68 ms 14784 KB Output is correct
15 Correct 70 ms 18368 KB Output is correct
16 Correct 67 ms 18884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 348 KB Output is correct
7 Correct 0 ms 348 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 1 ms 344 KB Output is correct
15 Correct 2 ms 344 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 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 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 420 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 64 ms 17944 KB Output is correct
30 Correct 85 ms 25284 KB Output is correct
31 Correct 61 ms 14020 KB Output is correct
32 Correct 71 ms 18312 KB Output is correct
33 Correct 76 ms 17756 KB Output is correct
34 Correct 64 ms 15400 KB Output is correct
35 Correct 64 ms 16920 KB Output is correct
36 Correct 102 ms 18620 KB Output is correct
37 Correct 86 ms 17348 KB Output is correct
38 Correct 75 ms 18524 KB Output is correct
39 Correct 62 ms 12736 KB Output is correct
40 Correct 68 ms 14784 KB Output is correct
41 Correct 70 ms 18368 KB Output is correct
42 Correct 67 ms 18884 KB Output is correct
43 Correct 735 ms 18528 KB Output is correct
44 Correct 892 ms 25340 KB Output is correct
45 Correct 857 ms 23744 KB Output is correct
46 Correct 641 ms 18372 KB Output is correct
47 Correct 664 ms 18112 KB Output is correct
48 Correct 208 ms 16832 KB Output is correct
49 Correct 276 ms 18884 KB Output is correct
50 Correct 449 ms 16728 KB Output is correct
51 Correct 616 ms 18468 KB Output is correct
52 Correct 707 ms 18968 KB Output is correct
53 Correct 290 ms 12996 KB Output is correct
54 Correct 712 ms 15800 KB Output is correct
55 Correct 788 ms 18620 KB Output is correct
56 Correct 822 ms 18880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 348 KB Output is correct
7 Correct 0 ms 348 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 1 ms 344 KB Output is correct
15 Correct 2 ms 344 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 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 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 420 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 10 ms 604 KB Output is correct
30 Correct 6 ms 604 KB Output is correct
31 Correct 6 ms 604 KB Output is correct
32 Correct 4 ms 604 KB Output is correct
33 Correct 3 ms 608 KB Output is correct
34 Correct 6 ms 604 KB Output is correct
35 Correct 6 ms 604 KB Output is correct
36 Correct 5 ms 604 KB Output is correct
37 Correct 9 ms 604 KB Output is correct
38 Correct 11 ms 724 KB Output is correct
39 Correct 11 ms 640 KB Output is correct
40 Correct 5 ms 604 KB Output is correct
41 Correct 5 ms 604 KB Output is correct
42 Correct 5 ms 656 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 4 ms 600 KB Output is correct
46 Correct 4 ms 604 KB Output is correct
47 Correct 6 ms 604 KB Output is correct
48 Correct 5 ms 604 KB Output is correct
49 Correct 6 ms 656 KB Output is correct
50 Correct 5 ms 604 KB Output is correct
51 Correct 6 ms 604 KB Output is correct
52 Correct 5 ms 604 KB Output is correct
53 Correct 8 ms 604 KB Output is correct
54 Correct 6 ms 604 KB Output is correct
55 Execution timed out 2029 ms 9524 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 348 KB Output is correct
7 Correct 0 ms 348 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 1 ms 344 KB Output is correct
15 Correct 2 ms 344 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 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 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 420 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 10 ms 604 KB Output is correct
30 Correct 6 ms 604 KB Output is correct
31 Correct 6 ms 604 KB Output is correct
32 Correct 4 ms 604 KB Output is correct
33 Correct 3 ms 608 KB Output is correct
34 Correct 6 ms 604 KB Output is correct
35 Correct 6 ms 604 KB Output is correct
36 Correct 5 ms 604 KB Output is correct
37 Correct 9 ms 604 KB Output is correct
38 Correct 11 ms 724 KB Output is correct
39 Correct 11 ms 640 KB Output is correct
40 Correct 5 ms 604 KB Output is correct
41 Correct 5 ms 604 KB Output is correct
42 Correct 5 ms 656 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 4 ms 600 KB Output is correct
46 Correct 4 ms 604 KB Output is correct
47 Correct 6 ms 604 KB Output is correct
48 Correct 5 ms 604 KB Output is correct
49 Correct 6 ms 656 KB Output is correct
50 Correct 5 ms 604 KB Output is correct
51 Correct 6 ms 604 KB Output is correct
52 Correct 5 ms 604 KB Output is correct
53 Correct 8 ms 604 KB Output is correct
54 Correct 6 ms 604 KB Output is correct
55 Correct 64 ms 17944 KB Output is correct
56 Correct 85 ms 25284 KB Output is correct
57 Correct 61 ms 14020 KB Output is correct
58 Correct 71 ms 18312 KB Output is correct
59 Correct 76 ms 17756 KB Output is correct
60 Correct 64 ms 15400 KB Output is correct
61 Correct 64 ms 16920 KB Output is correct
62 Correct 102 ms 18620 KB Output is correct
63 Correct 86 ms 17348 KB Output is correct
64 Correct 75 ms 18524 KB Output is correct
65 Correct 62 ms 12736 KB Output is correct
66 Correct 68 ms 14784 KB Output is correct
67 Correct 70 ms 18368 KB Output is correct
68 Correct 67 ms 18884 KB Output is correct
69 Correct 735 ms 18528 KB Output is correct
70 Correct 892 ms 25340 KB Output is correct
71 Correct 857 ms 23744 KB Output is correct
72 Correct 641 ms 18372 KB Output is correct
73 Correct 664 ms 18112 KB Output is correct
74 Correct 208 ms 16832 KB Output is correct
75 Correct 276 ms 18884 KB Output is correct
76 Correct 449 ms 16728 KB Output is correct
77 Correct 616 ms 18468 KB Output is correct
78 Correct 707 ms 18968 KB Output is correct
79 Correct 290 ms 12996 KB Output is correct
80 Correct 712 ms 15800 KB Output is correct
81 Correct 788 ms 18620 KB Output is correct
82 Correct 822 ms 18880 KB Output is correct
83 Execution timed out 2029 ms 9524 KB Time limit exceeded
84 Halted 0 ms 0 KB -