Submission #1039439

# Submission time Handle Problem Language Result Execution time Memory
1039439 2024-07-30T21:36:07 Z MarwenElarbi Joker (BOI20_joker) C++17
100 / 100
720 ms 34488 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define se second
#define fi first
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const int nax = 2e5 + 5;
vector<int> adj[nax];
vector<pair<int,int>> edges(nax);
int opt[nax];
struct DSU{
    vector<pair<int,int>> parent;
    vector<vector<int>> hist;
    vector<int> rank;
    bool bip=true;
    void init(int n){
        parent.resize(n);
        rank.assign(n,0);
        for (int i = 0; i < n; ++i)
        {
            parent[i]={i,0};
        }
        return;
    }
    bool is_bip(){
        return bip;
    }
    pair<int,int> find(int x){
        if(x!=parent[x].fi){
            int len=parent[x].se;
            pair<int,int> v=find(parent[x].fi);
            v.se=(v.se+len)%2;
            return v;
        }
        return parent[x];
    }
    void join(int x,int y){
        if(x==y)
            return;
        pair<int,int> xx=find(x);
        pair<int,int> yy=find(y);
        if(xx.fi==yy.fi){
            hist.pb({-1,bip});
            if(xx.se==yy.se){
                bip=0;
            }
            return;
        }
        if(rank[xx.fi]<rank[yy.fi]) swap(xx,yy);
        hist.pb({yy.fi,parent[yy.fi].fi,parent[yy.fi].se,xx.fi,(rank[xx.fi]==rank[yy.fi])});
        parent[yy.fi].fi=xx.fi;
        parent[yy.fi].se=(yy.se+xx.se+1)%2;
        rank[xx.fi]+=(rank[xx.fi]==rank[yy.fi]);
    }
    void roll_back(){
        auto last=hist.back();
        hist.pop_back();
        if(last[0]==-1){
            bip=last.back();
        }else{
            parent[last[0]]={last[1],last[2]};
            rank[last[3]]-=last[4];
        }
    }
    void roll_back(int x){
        while(x--){
            roll_back();
        }
    }
}dsu;
int n,m,q;
void daq(int l,int r,int optl,int optr){
    if(l>r) return;
    int mid=(r+l)/2;
    int cnt=0;
    for (int i = l; i < mid; ++i)
    {
        cnt++;
        dsu.join(edges[i].fi,edges[i].se);
    }
    int optimum=optr;
    for (int i = optr; i >= max(mid,optl) ; --i)
    {
        if(!dsu.is_bip()){
            break;
        }
        optimum=i;
        if(i<m){
            cnt++;
            dsu.join(edges[i].fi,edges[i].se);
        }
    }
    opt[mid]=optimum;
    dsu.roll_back(cnt);
    cnt=0;
    for (int i = optimum; i <= optr; ++i)
    {
        if(i==m) continue;
        cnt++;
        dsu.join(edges[i].fi,edges[i].se);
    }
    daq(l,mid-1,optl,optimum);
    dsu.roll_back(cnt);
    cnt=0;
    for (int i = l; i <= mid; ++i)
    {
        cnt++;
        dsu.join(edges[i].fi,edges[i].se);
    }
    daq(mid+1,r,optimum,optr);
    dsu.roll_back(cnt);
    cnt=0;
}
int main(){
    cin>>n>>m>>q;
    dsu.init(n);
    for (int i = 0; i < m; ++i)
    {
        int x,y;
        cin>>x>>y;
        x--;y--;
        edges[i]={x,y};
        adj[x].pb(y);
        adj[y].pb(x);
    }
    daq(0,m-1,0,m);
    for (int i = 0; i < q; ++i)
    {
        int x,y;
        cin>>x>>y;
        x--;y--;
        cout << (opt[x] > y ? "YES" : "NO")<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7256 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 3 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 3 ms 7260 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 5 ms 7260 KB Output is correct
14 Correct 3 ms 7260 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 3 ms 7512 KB Output is correct
18 Correct 2 ms 7256 KB Output is correct
19 Correct 3 ms 7256 KB Output is correct
20 Correct 3 ms 7324 KB Output is correct
21 Correct 3 ms 7256 KB Output is correct
22 Correct 2 ms 7260 KB Output is correct
23 Correct 2 ms 7260 KB Output is correct
24 Correct 2 ms 7260 KB Output is correct
25 Correct 2 ms 7260 KB Output is correct
26 Correct 2 ms 7260 KB Output is correct
27 Correct 2 ms 7260 KB Output is correct
28 Correct 2 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7256 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 3 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 3 ms 7260 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 5 ms 7260 KB Output is correct
14 Correct 3 ms 7260 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 3 ms 7512 KB Output is correct
18 Correct 2 ms 7256 KB Output is correct
19 Correct 3 ms 7256 KB Output is correct
20 Correct 3 ms 7324 KB Output is correct
21 Correct 3 ms 7256 KB Output is correct
22 Correct 2 ms 7260 KB Output is correct
23 Correct 2 ms 7260 KB Output is correct
24 Correct 2 ms 7260 KB Output is correct
25 Correct 2 ms 7260 KB Output is correct
26 Correct 2 ms 7260 KB Output is correct
27 Correct 2 ms 7260 KB Output is correct
28 Correct 2 ms 7260 KB Output is correct
29 Correct 6 ms 7260 KB Output is correct
30 Correct 7 ms 7516 KB Output is correct
31 Correct 7 ms 7336 KB Output is correct
32 Correct 10 ms 7516 KB Output is correct
33 Correct 6 ms 7516 KB Output is correct
34 Correct 7 ms 7516 KB Output is correct
35 Correct 7 ms 7516 KB Output is correct
36 Correct 7 ms 7392 KB Output is correct
37 Correct 8 ms 7512 KB Output is correct
38 Correct 10 ms 7516 KB Output is correct
39 Correct 6 ms 7516 KB Output is correct
40 Correct 7 ms 7516 KB Output is correct
41 Correct 6 ms 7516 KB Output is correct
42 Correct 7 ms 7516 KB Output is correct
43 Correct 7 ms 7516 KB Output is correct
44 Correct 6 ms 7516 KB Output is correct
45 Correct 7 ms 7516 KB Output is correct
46 Correct 7 ms 7340 KB Output is correct
47 Correct 6 ms 7516 KB Output is correct
48 Correct 7 ms 7516 KB Output is correct
49 Correct 7 ms 7768 KB Output is correct
50 Correct 7 ms 7560 KB Output is correct
51 Correct 7 ms 7344 KB Output is correct
52 Correct 7 ms 7512 KB Output is correct
53 Correct 8 ms 7516 KB Output is correct
54 Correct 7 ms 7564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 577 ms 23344 KB Output is correct
4 Correct 714 ms 27892 KB Output is correct
5 Correct 566 ms 27180 KB Output is correct
6 Correct 646 ms 24496 KB Output is correct
7 Correct 588 ms 24484 KB Output is correct
8 Correct 587 ms 23624 KB Output is correct
9 Correct 611 ms 24260 KB Output is correct
10 Correct 667 ms 27116 KB Output is correct
11 Correct 576 ms 24248 KB Output is correct
12 Correct 590 ms 27812 KB Output is correct
13 Correct 534 ms 22464 KB Output is correct
14 Correct 556 ms 23220 KB Output is correct
15 Correct 622 ms 25536 KB Output is correct
16 Correct 642 ms 27892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7256 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 3 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 3 ms 7260 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 5 ms 7260 KB Output is correct
14 Correct 3 ms 7260 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 3 ms 7512 KB Output is correct
18 Correct 2 ms 7256 KB Output is correct
19 Correct 3 ms 7256 KB Output is correct
20 Correct 3 ms 7324 KB Output is correct
21 Correct 3 ms 7256 KB Output is correct
22 Correct 2 ms 7260 KB Output is correct
23 Correct 2 ms 7260 KB Output is correct
24 Correct 2 ms 7260 KB Output is correct
25 Correct 2 ms 7260 KB Output is correct
26 Correct 2 ms 7260 KB Output is correct
27 Correct 2 ms 7260 KB Output is correct
28 Correct 2 ms 7260 KB Output is correct
29 Correct 577 ms 23344 KB Output is correct
30 Correct 714 ms 27892 KB Output is correct
31 Correct 566 ms 27180 KB Output is correct
32 Correct 646 ms 24496 KB Output is correct
33 Correct 588 ms 24484 KB Output is correct
34 Correct 587 ms 23624 KB Output is correct
35 Correct 611 ms 24260 KB Output is correct
36 Correct 667 ms 27116 KB Output is correct
37 Correct 576 ms 24248 KB Output is correct
38 Correct 590 ms 27812 KB Output is correct
39 Correct 534 ms 22464 KB Output is correct
40 Correct 556 ms 23220 KB Output is correct
41 Correct 622 ms 25536 KB Output is correct
42 Correct 642 ms 27892 KB Output is correct
43 Correct 518 ms 27612 KB Output is correct
44 Correct 667 ms 31480 KB Output is correct
45 Correct 618 ms 31964 KB Output is correct
46 Correct 585 ms 28272 KB Output is correct
47 Correct 571 ms 29376 KB Output is correct
48 Correct 647 ms 28668 KB Output is correct
49 Correct 653 ms 31020 KB Output is correct
50 Correct 617 ms 27580 KB Output is correct
51 Correct 633 ms 30964 KB Output is correct
52 Correct 633 ms 32452 KB Output is correct
53 Correct 591 ms 27320 KB Output is correct
54 Correct 649 ms 29040 KB Output is correct
55 Correct 720 ms 29960 KB Output is correct
56 Correct 712 ms 31616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7256 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 3 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 3 ms 7260 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 5 ms 7260 KB Output is correct
14 Correct 3 ms 7260 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 3 ms 7512 KB Output is correct
18 Correct 2 ms 7256 KB Output is correct
19 Correct 3 ms 7256 KB Output is correct
20 Correct 3 ms 7324 KB Output is correct
21 Correct 3 ms 7256 KB Output is correct
22 Correct 2 ms 7260 KB Output is correct
23 Correct 2 ms 7260 KB Output is correct
24 Correct 2 ms 7260 KB Output is correct
25 Correct 2 ms 7260 KB Output is correct
26 Correct 2 ms 7260 KB Output is correct
27 Correct 2 ms 7260 KB Output is correct
28 Correct 2 ms 7260 KB Output is correct
29 Correct 6 ms 7260 KB Output is correct
30 Correct 7 ms 7516 KB Output is correct
31 Correct 7 ms 7336 KB Output is correct
32 Correct 10 ms 7516 KB Output is correct
33 Correct 6 ms 7516 KB Output is correct
34 Correct 7 ms 7516 KB Output is correct
35 Correct 7 ms 7516 KB Output is correct
36 Correct 7 ms 7392 KB Output is correct
37 Correct 8 ms 7512 KB Output is correct
38 Correct 10 ms 7516 KB Output is correct
39 Correct 6 ms 7516 KB Output is correct
40 Correct 7 ms 7516 KB Output is correct
41 Correct 6 ms 7516 KB Output is correct
42 Correct 7 ms 7516 KB Output is correct
43 Correct 7 ms 7516 KB Output is correct
44 Correct 6 ms 7516 KB Output is correct
45 Correct 7 ms 7516 KB Output is correct
46 Correct 7 ms 7340 KB Output is correct
47 Correct 6 ms 7516 KB Output is correct
48 Correct 7 ms 7516 KB Output is correct
49 Correct 7 ms 7768 KB Output is correct
50 Correct 7 ms 7560 KB Output is correct
51 Correct 7 ms 7344 KB Output is correct
52 Correct 7 ms 7512 KB Output is correct
53 Correct 8 ms 7516 KB Output is correct
54 Correct 7 ms 7564 KB Output is correct
55 Correct 312 ms 25860 KB Output is correct
56 Correct 457 ms 30452 KB Output is correct
57 Correct 294 ms 29404 KB Output is correct
58 Correct 344 ms 26312 KB Output is correct
59 Correct 398 ms 26048 KB Output is correct
60 Correct 479 ms 28672 KB Output is correct
61 Correct 410 ms 26300 KB Output is correct
62 Correct 433 ms 29376 KB Output is correct
63 Correct 330 ms 24764 KB Output is correct
64 Correct 421 ms 27076 KB Output is correct
65 Correct 472 ms 28920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7256 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 3 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 3 ms 7260 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 5 ms 7260 KB Output is correct
14 Correct 3 ms 7260 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 3 ms 7512 KB Output is correct
18 Correct 2 ms 7256 KB Output is correct
19 Correct 3 ms 7256 KB Output is correct
20 Correct 3 ms 7324 KB Output is correct
21 Correct 3 ms 7256 KB Output is correct
22 Correct 2 ms 7260 KB Output is correct
23 Correct 2 ms 7260 KB Output is correct
24 Correct 2 ms 7260 KB Output is correct
25 Correct 2 ms 7260 KB Output is correct
26 Correct 2 ms 7260 KB Output is correct
27 Correct 2 ms 7260 KB Output is correct
28 Correct 2 ms 7260 KB Output is correct
29 Correct 6 ms 7260 KB Output is correct
30 Correct 7 ms 7516 KB Output is correct
31 Correct 7 ms 7336 KB Output is correct
32 Correct 10 ms 7516 KB Output is correct
33 Correct 6 ms 7516 KB Output is correct
34 Correct 7 ms 7516 KB Output is correct
35 Correct 7 ms 7516 KB Output is correct
36 Correct 7 ms 7392 KB Output is correct
37 Correct 8 ms 7512 KB Output is correct
38 Correct 10 ms 7516 KB Output is correct
39 Correct 6 ms 7516 KB Output is correct
40 Correct 7 ms 7516 KB Output is correct
41 Correct 6 ms 7516 KB Output is correct
42 Correct 7 ms 7516 KB Output is correct
43 Correct 7 ms 7516 KB Output is correct
44 Correct 6 ms 7516 KB Output is correct
45 Correct 7 ms 7516 KB Output is correct
46 Correct 7 ms 7340 KB Output is correct
47 Correct 6 ms 7516 KB Output is correct
48 Correct 7 ms 7516 KB Output is correct
49 Correct 7 ms 7768 KB Output is correct
50 Correct 7 ms 7560 KB Output is correct
51 Correct 7 ms 7344 KB Output is correct
52 Correct 7 ms 7512 KB Output is correct
53 Correct 8 ms 7516 KB Output is correct
54 Correct 7 ms 7564 KB Output is correct
55 Correct 577 ms 23344 KB Output is correct
56 Correct 714 ms 27892 KB Output is correct
57 Correct 566 ms 27180 KB Output is correct
58 Correct 646 ms 24496 KB Output is correct
59 Correct 588 ms 24484 KB Output is correct
60 Correct 587 ms 23624 KB Output is correct
61 Correct 611 ms 24260 KB Output is correct
62 Correct 667 ms 27116 KB Output is correct
63 Correct 576 ms 24248 KB Output is correct
64 Correct 590 ms 27812 KB Output is correct
65 Correct 534 ms 22464 KB Output is correct
66 Correct 556 ms 23220 KB Output is correct
67 Correct 622 ms 25536 KB Output is correct
68 Correct 642 ms 27892 KB Output is correct
69 Correct 518 ms 27612 KB Output is correct
70 Correct 667 ms 31480 KB Output is correct
71 Correct 618 ms 31964 KB Output is correct
72 Correct 585 ms 28272 KB Output is correct
73 Correct 571 ms 29376 KB Output is correct
74 Correct 647 ms 28668 KB Output is correct
75 Correct 653 ms 31020 KB Output is correct
76 Correct 617 ms 27580 KB Output is correct
77 Correct 633 ms 30964 KB Output is correct
78 Correct 633 ms 32452 KB Output is correct
79 Correct 591 ms 27320 KB Output is correct
80 Correct 649 ms 29040 KB Output is correct
81 Correct 720 ms 29960 KB Output is correct
82 Correct 712 ms 31616 KB Output is correct
83 Correct 312 ms 25860 KB Output is correct
84 Correct 457 ms 30452 KB Output is correct
85 Correct 294 ms 29404 KB Output is correct
86 Correct 344 ms 26312 KB Output is correct
87 Correct 398 ms 26048 KB Output is correct
88 Correct 479 ms 28672 KB Output is correct
89 Correct 410 ms 26300 KB Output is correct
90 Correct 433 ms 29376 KB Output is correct
91 Correct 330 ms 24764 KB Output is correct
92 Correct 421 ms 27076 KB Output is correct
93 Correct 472 ms 28920 KB Output is correct
94 Correct 593 ms 28408 KB Output is correct
95 Correct 612 ms 34084 KB Output is correct
96 Correct 529 ms 33112 KB Output is correct
97 Correct 537 ms 28864 KB Output is correct
98 Correct 554 ms 29952 KB Output is correct
99 Correct 583 ms 28596 KB Output is correct
100 Correct 653 ms 32420 KB Output is correct
101 Correct 568 ms 28348 KB Output is correct
102 Correct 622 ms 30164 KB Output is correct
103 Correct 674 ms 33520 KB Output is correct
104 Correct 573 ms 27672 KB Output is correct
105 Correct 642 ms 29828 KB Output is correct
106 Correct 689 ms 32508 KB Output is correct
107 Correct 521 ms 34488 KB Output is correct
108 Correct 561 ms 28276 KB Output is correct
109 Correct 531 ms 28920 KB Output is correct
110 Correct 543 ms 28408 KB Output is correct
111 Correct 584 ms 29532 KB Output is correct
112 Correct 564 ms 28920 KB Output is correct
113 Correct 601 ms 28764 KB Output is correct
114 Correct 565 ms 28256 KB Output is correct
115 Correct 572 ms 29556 KB Output is correct
116 Correct 567 ms 28680 KB Output is correct