답안 #964016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964016 2024-04-16T07:53:04 Z owoovo Joker (BOI20_joker) C++17
100 / 100
251 ms 65732 KB
#include<bits/stdc++.h>
#pragma GCC opitimize("O3,unroll-loops")
#define ll long long
#define F first 
#define S second
using namespace std;
vector<pair<int,int>> node[800010];
vector<pair<int,int>> edge;
int cnt,R,U;
int ans[200010];
struct Dsu{
    int ori[400100],si[400100];
    stack<pair<pair<int,int>,int>> move;
    inline void init(){
        for(int i=0;i<=400050;i++)ori[i]=i,si[i]=1;
        while(!move.empty())move.pop();
    }
    inline int f(int a){
        return ori[a]==a?a:f(ori[a]);
    }
    inline bool onion(int a,int b,int id){
        a=f(a),b=f(b);
        if(a==b)return false;
        if(si[a]>si[b])swap(a,b);
        ori[a]=b;
        si[b]+=si[a];
        move.push({{a,b},id});
        return true;
    }
    inline void undo(){
        auto [p,id]=move.top();
        auto [a,b]=p;
        ori[a]=a;
        si[b]-=si[a];
        move.pop();
        return;
    }
}dsu;
inline bool addedge(int u,int v,int id){
    if(dsu.onion(u*2,v*2+1,id)^dsu.onion(u*2+1,v*2,id))return false;
    else return true;
}
inline void add(int l,int r,int nl,int nr,int id,int u,int v){
    if(l==nl&&r==nr){
        node[id].push_back({u,v});
        return ;
    }
    int m=(nl+nr)>>1;
    if(r<=m){
        add(l,r,nl,m,id*2+1,u,v);
    }else if(m<l){
        add(l,r,m+1,nr,id*2+2,u,v);
    }else{
        add(l,m,nl,m,id*2+1,u,v);
        add(m+1,r,m+1,nr,id*2+2,u,v);
    }
    return;
}
inline void vis(int l,int r,int id){
    for(auto x:node[id]){
        addedge(x.F,x.S,id);
    }
    if(l==r){
        int gogo=R,L=U-l;
        while(gogo>L){
            if(addedge(edge[gogo].F,edge[gogo].S,id)==false){
                break;
            }else{
                gogo--;
            }
        }
        gogo++;
        ans[U-l]=gogo;
        for(int i=R;i>=gogo;i--){
            if(l+1<=U)add(l+1,U,0,U,0,edge[i].F,edge[i].S);
        }
        R=gogo-1;
        while(!dsu.move.empty()&&dsu.move.top().S==id)dsu.undo();
        return;
    }
    int m=(l+r)>>1;
    vis(l,m,id*2+1);
    vis(m+1,r,id*2+2);
    while(!dsu.move.empty()&&dsu.move.top().S==id)dsu.undo();
    return;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n,m,q;
    cin>>n>>m>>q;
    U=1;
    R=m;
    dsu.init();
    edge.push_back({0,0});
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        edge.push_back({u,v});
    }
    while(U<=m){
        if(addedge(edge[U].F,edge[U].S,0)==false){
            break;
        }else{
            U++;
        }
    }
    U--;
    if(U==m){
        for(int i=0;i<q;i++){
            cout<<"NO\n";
        }
        return 0;
    }
    dsu.init();
    for(int i=1;i<=U;i++){
        add(0,U-i,0,U,0,edge[i].F,edge[i].S);
    }
    for(int i=U+1;i<=m;i++)ans[i]=m+5;
    vis(0,U,0);
    // for(int i=0;i<=m;i++){
    //     cout<<ans[i]<<" ";
    // }
    // cout<<"\n";
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;
        l--;
        r++;
        if(r>=ans[l]){
            cout<<"NO\n";
        }else{
            cout<<"YES\n";
        }
    }
    return 0;
}

Compilation message

Joker.cpp:2: warning: ignoring '#pragma GCC opitimize' [-Wunknown-pragmas]
    2 | #pragma GCC opitimize("O3,unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22364 KB Output is correct
2 Correct 11 ms 22364 KB Output is correct
3 Correct 12 ms 22376 KB Output is correct
4 Correct 11 ms 22380 KB Output is correct
5 Correct 12 ms 22360 KB Output is correct
6 Correct 11 ms 22364 KB Output is correct
7 Correct 11 ms 22360 KB Output is correct
8 Correct 11 ms 22364 KB Output is correct
9 Correct 12 ms 22364 KB Output is correct
10 Correct 11 ms 22364 KB Output is correct
11 Correct 12 ms 22296 KB Output is correct
12 Correct 11 ms 22364 KB Output is correct
13 Correct 11 ms 22364 KB Output is correct
14 Correct 11 ms 22360 KB Output is correct
15 Correct 11 ms 22360 KB Output is correct
16 Correct 13 ms 22360 KB Output is correct
17 Correct 12 ms 22400 KB Output is correct
18 Correct 11 ms 22364 KB Output is correct
19 Correct 13 ms 22364 KB Output is correct
20 Correct 12 ms 22216 KB Output is correct
21 Correct 12 ms 22364 KB Output is correct
22 Correct 12 ms 22364 KB Output is correct
23 Correct 13 ms 22364 KB Output is correct
24 Correct 11 ms 22364 KB Output is correct
25 Correct 11 ms 22372 KB Output is correct
26 Correct 14 ms 22296 KB Output is correct
27 Correct 11 ms 22360 KB Output is correct
28 Correct 14 ms 22364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22364 KB Output is correct
2 Correct 11 ms 22364 KB Output is correct
3 Correct 12 ms 22376 KB Output is correct
4 Correct 11 ms 22380 KB Output is correct
5 Correct 12 ms 22360 KB Output is correct
6 Correct 11 ms 22364 KB Output is correct
7 Correct 11 ms 22360 KB Output is correct
8 Correct 11 ms 22364 KB Output is correct
9 Correct 12 ms 22364 KB Output is correct
10 Correct 11 ms 22364 KB Output is correct
11 Correct 12 ms 22296 KB Output is correct
12 Correct 11 ms 22364 KB Output is correct
13 Correct 11 ms 22364 KB Output is correct
14 Correct 11 ms 22360 KB Output is correct
15 Correct 11 ms 22360 KB Output is correct
16 Correct 13 ms 22360 KB Output is correct
17 Correct 12 ms 22400 KB Output is correct
18 Correct 11 ms 22364 KB Output is correct
19 Correct 13 ms 22364 KB Output is correct
20 Correct 12 ms 22216 KB Output is correct
21 Correct 12 ms 22364 KB Output is correct
22 Correct 12 ms 22364 KB Output is correct
23 Correct 13 ms 22364 KB Output is correct
24 Correct 11 ms 22364 KB Output is correct
25 Correct 11 ms 22372 KB Output is correct
26 Correct 14 ms 22296 KB Output is correct
27 Correct 11 ms 22360 KB Output is correct
28 Correct 14 ms 22364 KB Output is correct
29 Correct 12 ms 22360 KB Output is correct
30 Correct 13 ms 22616 KB Output is correct
31 Correct 13 ms 22364 KB Output is correct
32 Correct 13 ms 22620 KB Output is correct
33 Correct 12 ms 22340 KB Output is correct
34 Correct 14 ms 22620 KB Output is correct
35 Correct 13 ms 22620 KB Output is correct
36 Correct 12 ms 22364 KB Output is correct
37 Correct 13 ms 22664 KB Output is correct
38 Correct 11 ms 22364 KB Output is correct
39 Correct 14 ms 22364 KB Output is correct
40 Correct 12 ms 22340 KB Output is correct
41 Correct 12 ms 22364 KB Output is correct
42 Correct 12 ms 22380 KB Output is correct
43 Correct 13 ms 22360 KB Output is correct
44 Correct 13 ms 22364 KB Output is correct
45 Correct 13 ms 22452 KB Output is correct
46 Correct 14 ms 22616 KB Output is correct
47 Correct 11 ms 22364 KB Output is correct
48 Correct 12 ms 22364 KB Output is correct
49 Correct 13 ms 22364 KB Output is correct
50 Correct 13 ms 22620 KB Output is correct
51 Correct 13 ms 22364 KB Output is correct
52 Correct 14 ms 22364 KB Output is correct
53 Correct 13 ms 22360 KB Output is correct
54 Correct 13 ms 22580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22364 KB Output is correct
2 Correct 11 ms 22364 KB Output is correct
3 Correct 197 ms 50932 KB Output is correct
4 Correct 58 ms 31700 KB Output is correct
5 Correct 185 ms 52676 KB Output is correct
6 Correct 129 ms 44104 KB Output is correct
7 Correct 148 ms 43736 KB Output is correct
8 Correct 161 ms 44900 KB Output is correct
9 Correct 173 ms 45904 KB Output is correct
10 Correct 195 ms 49604 KB Output is correct
11 Correct 169 ms 47816 KB Output is correct
12 Correct 163 ms 48524 KB Output is correct
13 Correct 152 ms 44640 KB Output is correct
14 Correct 170 ms 45140 KB Output is correct
15 Correct 173 ms 47780 KB Output is correct
16 Correct 233 ms 49860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22364 KB Output is correct
2 Correct 11 ms 22364 KB Output is correct
3 Correct 12 ms 22376 KB Output is correct
4 Correct 11 ms 22380 KB Output is correct
5 Correct 12 ms 22360 KB Output is correct
6 Correct 11 ms 22364 KB Output is correct
7 Correct 11 ms 22360 KB Output is correct
8 Correct 11 ms 22364 KB Output is correct
9 Correct 12 ms 22364 KB Output is correct
10 Correct 11 ms 22364 KB Output is correct
11 Correct 12 ms 22296 KB Output is correct
12 Correct 11 ms 22364 KB Output is correct
13 Correct 11 ms 22364 KB Output is correct
14 Correct 11 ms 22360 KB Output is correct
15 Correct 11 ms 22360 KB Output is correct
16 Correct 13 ms 22360 KB Output is correct
17 Correct 12 ms 22400 KB Output is correct
18 Correct 11 ms 22364 KB Output is correct
19 Correct 13 ms 22364 KB Output is correct
20 Correct 12 ms 22216 KB Output is correct
21 Correct 12 ms 22364 KB Output is correct
22 Correct 12 ms 22364 KB Output is correct
23 Correct 13 ms 22364 KB Output is correct
24 Correct 11 ms 22364 KB Output is correct
25 Correct 11 ms 22372 KB Output is correct
26 Correct 14 ms 22296 KB Output is correct
27 Correct 11 ms 22360 KB Output is correct
28 Correct 14 ms 22364 KB Output is correct
29 Correct 197 ms 50932 KB Output is correct
30 Correct 58 ms 31700 KB Output is correct
31 Correct 185 ms 52676 KB Output is correct
32 Correct 129 ms 44104 KB Output is correct
33 Correct 148 ms 43736 KB Output is correct
34 Correct 161 ms 44900 KB Output is correct
35 Correct 173 ms 45904 KB Output is correct
36 Correct 195 ms 49604 KB Output is correct
37 Correct 169 ms 47816 KB Output is correct
38 Correct 163 ms 48524 KB Output is correct
39 Correct 152 ms 44640 KB Output is correct
40 Correct 170 ms 45140 KB Output is correct
41 Correct 173 ms 47780 KB Output is correct
42 Correct 233 ms 49860 KB Output is correct
43 Correct 179 ms 51988 KB Output is correct
44 Correct 57 ms 32068 KB Output is correct
45 Correct 231 ms 64712 KB Output is correct
46 Correct 127 ms 44484 KB Output is correct
47 Correct 132 ms 45568 KB Output is correct
48 Correct 174 ms 46148 KB Output is correct
49 Correct 197 ms 50228 KB Output is correct
50 Correct 144 ms 48340 KB Output is correct
51 Correct 164 ms 50888 KB Output is correct
52 Correct 176 ms 50084 KB Output is correct
53 Correct 144 ms 45824 KB Output is correct
54 Correct 171 ms 46360 KB Output is correct
55 Correct 186 ms 48500 KB Output is correct
56 Correct 188 ms 50372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22364 KB Output is correct
2 Correct 11 ms 22364 KB Output is correct
3 Correct 12 ms 22376 KB Output is correct
4 Correct 11 ms 22380 KB Output is correct
5 Correct 12 ms 22360 KB Output is correct
6 Correct 11 ms 22364 KB Output is correct
7 Correct 11 ms 22360 KB Output is correct
8 Correct 11 ms 22364 KB Output is correct
9 Correct 12 ms 22364 KB Output is correct
10 Correct 11 ms 22364 KB Output is correct
11 Correct 12 ms 22296 KB Output is correct
12 Correct 11 ms 22364 KB Output is correct
13 Correct 11 ms 22364 KB Output is correct
14 Correct 11 ms 22360 KB Output is correct
15 Correct 11 ms 22360 KB Output is correct
16 Correct 13 ms 22360 KB Output is correct
17 Correct 12 ms 22400 KB Output is correct
18 Correct 11 ms 22364 KB Output is correct
19 Correct 13 ms 22364 KB Output is correct
20 Correct 12 ms 22216 KB Output is correct
21 Correct 12 ms 22364 KB Output is correct
22 Correct 12 ms 22364 KB Output is correct
23 Correct 13 ms 22364 KB Output is correct
24 Correct 11 ms 22364 KB Output is correct
25 Correct 11 ms 22372 KB Output is correct
26 Correct 14 ms 22296 KB Output is correct
27 Correct 11 ms 22360 KB Output is correct
28 Correct 14 ms 22364 KB Output is correct
29 Correct 12 ms 22360 KB Output is correct
30 Correct 13 ms 22616 KB Output is correct
31 Correct 13 ms 22364 KB Output is correct
32 Correct 13 ms 22620 KB Output is correct
33 Correct 12 ms 22340 KB Output is correct
34 Correct 14 ms 22620 KB Output is correct
35 Correct 13 ms 22620 KB Output is correct
36 Correct 12 ms 22364 KB Output is correct
37 Correct 13 ms 22664 KB Output is correct
38 Correct 11 ms 22364 KB Output is correct
39 Correct 14 ms 22364 KB Output is correct
40 Correct 12 ms 22340 KB Output is correct
41 Correct 12 ms 22364 KB Output is correct
42 Correct 12 ms 22380 KB Output is correct
43 Correct 13 ms 22360 KB Output is correct
44 Correct 13 ms 22364 KB Output is correct
45 Correct 13 ms 22452 KB Output is correct
46 Correct 14 ms 22616 KB Output is correct
47 Correct 11 ms 22364 KB Output is correct
48 Correct 12 ms 22364 KB Output is correct
49 Correct 13 ms 22364 KB Output is correct
50 Correct 13 ms 22620 KB Output is correct
51 Correct 13 ms 22364 KB Output is correct
52 Correct 14 ms 22364 KB Output is correct
53 Correct 13 ms 22360 KB Output is correct
54 Correct 13 ms 22580 KB Output is correct
55 Correct 155 ms 49356 KB Output is correct
56 Correct 47 ms 31348 KB Output is correct
57 Correct 151 ms 50440 KB Output is correct
58 Correct 108 ms 41748 KB Output is correct
59 Correct 144 ms 44028 KB Output is correct
60 Correct 154 ms 46968 KB Output is correct
61 Correct 143 ms 46748 KB Output is correct
62 Correct 165 ms 48908 KB Output is correct
63 Correct 115 ms 42180 KB Output is correct
64 Correct 142 ms 45000 KB Output is correct
65 Correct 181 ms 47512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22364 KB Output is correct
2 Correct 11 ms 22364 KB Output is correct
3 Correct 12 ms 22376 KB Output is correct
4 Correct 11 ms 22380 KB Output is correct
5 Correct 12 ms 22360 KB Output is correct
6 Correct 11 ms 22364 KB Output is correct
7 Correct 11 ms 22360 KB Output is correct
8 Correct 11 ms 22364 KB Output is correct
9 Correct 12 ms 22364 KB Output is correct
10 Correct 11 ms 22364 KB Output is correct
11 Correct 12 ms 22296 KB Output is correct
12 Correct 11 ms 22364 KB Output is correct
13 Correct 11 ms 22364 KB Output is correct
14 Correct 11 ms 22360 KB Output is correct
15 Correct 11 ms 22360 KB Output is correct
16 Correct 13 ms 22360 KB Output is correct
17 Correct 12 ms 22400 KB Output is correct
18 Correct 11 ms 22364 KB Output is correct
19 Correct 13 ms 22364 KB Output is correct
20 Correct 12 ms 22216 KB Output is correct
21 Correct 12 ms 22364 KB Output is correct
22 Correct 12 ms 22364 KB Output is correct
23 Correct 13 ms 22364 KB Output is correct
24 Correct 11 ms 22364 KB Output is correct
25 Correct 11 ms 22372 KB Output is correct
26 Correct 14 ms 22296 KB Output is correct
27 Correct 11 ms 22360 KB Output is correct
28 Correct 14 ms 22364 KB Output is correct
29 Correct 12 ms 22360 KB Output is correct
30 Correct 13 ms 22616 KB Output is correct
31 Correct 13 ms 22364 KB Output is correct
32 Correct 13 ms 22620 KB Output is correct
33 Correct 12 ms 22340 KB Output is correct
34 Correct 14 ms 22620 KB Output is correct
35 Correct 13 ms 22620 KB Output is correct
36 Correct 12 ms 22364 KB Output is correct
37 Correct 13 ms 22664 KB Output is correct
38 Correct 11 ms 22364 KB Output is correct
39 Correct 14 ms 22364 KB Output is correct
40 Correct 12 ms 22340 KB Output is correct
41 Correct 12 ms 22364 KB Output is correct
42 Correct 12 ms 22380 KB Output is correct
43 Correct 13 ms 22360 KB Output is correct
44 Correct 13 ms 22364 KB Output is correct
45 Correct 13 ms 22452 KB Output is correct
46 Correct 14 ms 22616 KB Output is correct
47 Correct 11 ms 22364 KB Output is correct
48 Correct 12 ms 22364 KB Output is correct
49 Correct 13 ms 22364 KB Output is correct
50 Correct 13 ms 22620 KB Output is correct
51 Correct 13 ms 22364 KB Output is correct
52 Correct 14 ms 22364 KB Output is correct
53 Correct 13 ms 22360 KB Output is correct
54 Correct 13 ms 22580 KB Output is correct
55 Correct 197 ms 50932 KB Output is correct
56 Correct 58 ms 31700 KB Output is correct
57 Correct 185 ms 52676 KB Output is correct
58 Correct 129 ms 44104 KB Output is correct
59 Correct 148 ms 43736 KB Output is correct
60 Correct 161 ms 44900 KB Output is correct
61 Correct 173 ms 45904 KB Output is correct
62 Correct 195 ms 49604 KB Output is correct
63 Correct 169 ms 47816 KB Output is correct
64 Correct 163 ms 48524 KB Output is correct
65 Correct 152 ms 44640 KB Output is correct
66 Correct 170 ms 45140 KB Output is correct
67 Correct 173 ms 47780 KB Output is correct
68 Correct 233 ms 49860 KB Output is correct
69 Correct 179 ms 51988 KB Output is correct
70 Correct 57 ms 32068 KB Output is correct
71 Correct 231 ms 64712 KB Output is correct
72 Correct 127 ms 44484 KB Output is correct
73 Correct 132 ms 45568 KB Output is correct
74 Correct 174 ms 46148 KB Output is correct
75 Correct 197 ms 50228 KB Output is correct
76 Correct 144 ms 48340 KB Output is correct
77 Correct 164 ms 50888 KB Output is correct
78 Correct 176 ms 50084 KB Output is correct
79 Correct 144 ms 45824 KB Output is correct
80 Correct 171 ms 46360 KB Output is correct
81 Correct 186 ms 48500 KB Output is correct
82 Correct 188 ms 50372 KB Output is correct
83 Correct 155 ms 49356 KB Output is correct
84 Correct 47 ms 31348 KB Output is correct
85 Correct 151 ms 50440 KB Output is correct
86 Correct 108 ms 41748 KB Output is correct
87 Correct 144 ms 44028 KB Output is correct
88 Correct 154 ms 46968 KB Output is correct
89 Correct 143 ms 46748 KB Output is correct
90 Correct 165 ms 48908 KB Output is correct
91 Correct 115 ms 42180 KB Output is correct
92 Correct 142 ms 45000 KB Output is correct
93 Correct 181 ms 47512 KB Output is correct
94 Correct 178 ms 52680 KB Output is correct
95 Correct 251 ms 65732 KB Output is correct
96 Correct 172 ms 52304 KB Output is correct
97 Correct 135 ms 45816 KB Output is correct
98 Correct 137 ms 46592 KB Output is correct
99 Correct 158 ms 46260 KB Output is correct
100 Correct 172 ms 49708 KB Output is correct
101 Correct 158 ms 48328 KB Output is correct
102 Correct 179 ms 51144 KB Output is correct
103 Correct 188 ms 51492 KB Output is correct
104 Correct 145 ms 44648 KB Output is correct
105 Correct 178 ms 48584 KB Output is correct
106 Correct 196 ms 50684 KB Output is correct
107 Correct 173 ms 58024 KB Output is correct
108 Correct 169 ms 52260 KB Output is correct
109 Correct 167 ms 52424 KB Output is correct
110 Correct 166 ms 52344 KB Output is correct
111 Correct 169 ms 52428 KB Output is correct
112 Correct 166 ms 52296 KB Output is correct
113 Correct 181 ms 52420 KB Output is correct
114 Correct 162 ms 52420 KB Output is correct
115 Correct 174 ms 52460 KB Output is correct
116 Correct 164 ms 52292 KB Output is correct