답안 #990652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990652 2024-05-30T22:00:41 Z imarn Joker (BOI20_joker) C++14
100 / 100
247 ms 21176 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int mxn=4e5+5;
vector<pii>edge;
int pr[mxn]{0},m,n;
int dp[mxn]{0};
int sz[mxn]{0};
stack<pii>st;
void rollback(int x){
    while(st.size()>x){
        pr[st.top().f]=st.top().f;
        sz[st.top().s]-=sz[st.top().f];
        st.pop();
    }
}
int get(int r){
    return pr[r]==r?r:get(pr[r]);
}
void uni(int a,int b){
    a=get(a),b=get(b);
    if(a==b)return;
    if(sz[a]>sz[b])swap(a,b);
    pr[a]=b;sz[b]+=sz[a];
    st.push({a,b});
}
void solve(int l1,int r1,int l2,int r2){
    if(l1>r1)return;
    int md=(l1+r1)>>1,md2=-1;
    int pv1=st.size();
    for(int i=l1;i<=md-1;i++){
        uni(edge[i-1].f,edge[i-1].s+n);
        uni(edge[i-1].f+n,edge[i-1].s);
    }int pv2=st.size();
    for(int i=r2;i>=max(l2,md);i--){
        uni(edge[i-1].f,edge[i-1].s+n);
        uni(edge[i-1].f+n,edge[i-1].s);
        if(get(edge[i-1].f)==get(edge[i-1].f+n)||get(edge[i-1].s)==get(edge[i-1].s+n)){md2=i;break;}
    }if(md2==-1)md2=md-1;
    dp[md]=md2;rollback(pv2);uni(edge[md-1].f,edge[md-1].s+n);
    uni(edge[md-1].f+n,edge[md-1].s);
    solve(md+1,r1,md2,r2);
    rollback(pv1);
    for(int i=r2;i>=md2+1;i--){
        uni(edge[i-1].f,edge[i-1].s+n);
        uni(edge[i-1].f+n,edge[i-1].s);
    }
    solve(l1,md-1,l2,md2);rollback(pv1);
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int q;cin>>n>>m>>q;iota(pr,pr+2*n+1,0);
    for(int i=1;i<=2*n;i++)sz[i]=1;
    for(int i=0;i<m;i++){
        int u,v;cin>>u>>v;
        edge.pb({u,v});
    }solve(1,m,1,m);bool ok=0;
    for(int i=1;i<=m;i++){
        if(ok)dp[i]=m+1;
        uni(edge[i-1].f+n,edge[i-1].s);
        uni(edge[i-1].f,edge[i-1].s+n);
        if(get(edge[i-1].f)==get(edge[i-1].f+n)||get(edge[i-1].s)==get(edge[i-1].s+n))ok=1;
    }
    while(q--){
        int l,r;cin>>l>>r;
        cout<<(r<dp[l]?"YES\n":"NO\n");
    }
}

Compilation message

Joker.cpp: In function 'void rollback(int)':
Joker.cpp:16:20: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |     while(st.size()>x){
      |           ~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4560 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4560 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 2 ms 4564 KB Output is correct
31 Correct 2 ms 4700 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 2 ms 4680 KB Output is correct
35 Correct 2 ms 4700 KB Output is correct
36 Correct 2 ms 4700 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 2 ms 4584 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4444 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4700 KB Output is correct
46 Correct 2 ms 4700 KB Output is correct
47 Correct 2 ms 4576 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4696 KB Output is correct
50 Correct 2 ms 4712 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4700 KB Output is correct
54 Correct 2 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 125 ms 11712 KB Output is correct
4 Correct 217 ms 15360 KB Output is correct
5 Correct 114 ms 14528 KB Output is correct
6 Correct 137 ms 11712 KB Output is correct
7 Correct 149 ms 11712 KB Output is correct
8 Correct 145 ms 10432 KB Output is correct
9 Correct 171 ms 12520 KB Output is correct
10 Correct 244 ms 14780 KB Output is correct
11 Correct 146 ms 11708 KB Output is correct
12 Correct 170 ms 13756 KB Output is correct
13 Correct 143 ms 8900 KB Output is correct
14 Correct 143 ms 11200 KB Output is correct
15 Correct 229 ms 12692 KB Output is correct
16 Correct 244 ms 14272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4560 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 125 ms 11712 KB Output is correct
30 Correct 217 ms 15360 KB Output is correct
31 Correct 114 ms 14528 KB Output is correct
32 Correct 137 ms 11712 KB Output is correct
33 Correct 149 ms 11712 KB Output is correct
34 Correct 145 ms 10432 KB Output is correct
35 Correct 171 ms 12520 KB Output is correct
36 Correct 244 ms 14780 KB Output is correct
37 Correct 146 ms 11708 KB Output is correct
38 Correct 170 ms 13756 KB Output is correct
39 Correct 143 ms 8900 KB Output is correct
40 Correct 143 ms 11200 KB Output is correct
41 Correct 229 ms 12692 KB Output is correct
42 Correct 244 ms 14272 KB Output is correct
43 Correct 130 ms 16060 KB Output is correct
44 Correct 210 ms 19644 KB Output is correct
45 Correct 191 ms 19752 KB Output is correct
46 Correct 135 ms 16076 KB Output is correct
47 Correct 140 ms 16320 KB Output is correct
48 Correct 203 ms 15552 KB Output is correct
49 Correct 232 ms 18364 KB Output is correct
50 Correct 148 ms 15768 KB Output is correct
51 Correct 177 ms 17084 KB Output is correct
52 Correct 196 ms 19284 KB Output is correct
53 Correct 146 ms 13128 KB Output is correct
54 Correct 196 ms 15328 KB Output is correct
55 Correct 227 ms 17080 KB Output is correct
56 Correct 244 ms 18880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4560 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 2 ms 4564 KB Output is correct
31 Correct 2 ms 4700 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 2 ms 4680 KB Output is correct
35 Correct 2 ms 4700 KB Output is correct
36 Correct 2 ms 4700 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 2 ms 4584 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4444 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4700 KB Output is correct
46 Correct 2 ms 4700 KB Output is correct
47 Correct 2 ms 4576 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4696 KB Output is correct
50 Correct 2 ms 4712 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4700 KB Output is correct
54 Correct 2 ms 4700 KB Output is correct
55 Correct 107 ms 13484 KB Output is correct
56 Correct 189 ms 18076 KB Output is correct
57 Correct 92 ms 16324 KB Output is correct
58 Correct 121 ms 13884 KB Output is correct
59 Correct 174 ms 14020 KB Output is correct
60 Correct 229 ms 15044 KB Output is correct
61 Correct 154 ms 14016 KB Output is correct
62 Correct 177 ms 15820 KB Output is correct
63 Correct 122 ms 11212 KB Output is correct
64 Correct 189 ms 14800 KB Output is correct
65 Correct 228 ms 16580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4560 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 2 ms 4564 KB Output is correct
31 Correct 2 ms 4700 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 2 ms 4680 KB Output is correct
35 Correct 2 ms 4700 KB Output is correct
36 Correct 2 ms 4700 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 2 ms 4584 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4444 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4700 KB Output is correct
46 Correct 2 ms 4700 KB Output is correct
47 Correct 2 ms 4576 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4696 KB Output is correct
50 Correct 2 ms 4712 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4700 KB Output is correct
54 Correct 2 ms 4700 KB Output is correct
55 Correct 125 ms 11712 KB Output is correct
56 Correct 217 ms 15360 KB Output is correct
57 Correct 114 ms 14528 KB Output is correct
58 Correct 137 ms 11712 KB Output is correct
59 Correct 149 ms 11712 KB Output is correct
60 Correct 145 ms 10432 KB Output is correct
61 Correct 171 ms 12520 KB Output is correct
62 Correct 244 ms 14780 KB Output is correct
63 Correct 146 ms 11708 KB Output is correct
64 Correct 170 ms 13756 KB Output is correct
65 Correct 143 ms 8900 KB Output is correct
66 Correct 143 ms 11200 KB Output is correct
67 Correct 229 ms 12692 KB Output is correct
68 Correct 244 ms 14272 KB Output is correct
69 Correct 130 ms 16060 KB Output is correct
70 Correct 210 ms 19644 KB Output is correct
71 Correct 191 ms 19752 KB Output is correct
72 Correct 135 ms 16076 KB Output is correct
73 Correct 140 ms 16320 KB Output is correct
74 Correct 203 ms 15552 KB Output is correct
75 Correct 232 ms 18364 KB Output is correct
76 Correct 148 ms 15768 KB Output is correct
77 Correct 177 ms 17084 KB Output is correct
78 Correct 196 ms 19284 KB Output is correct
79 Correct 146 ms 13128 KB Output is correct
80 Correct 196 ms 15328 KB Output is correct
81 Correct 227 ms 17080 KB Output is correct
82 Correct 244 ms 18880 KB Output is correct
83 Correct 107 ms 13484 KB Output is correct
84 Correct 189 ms 18076 KB Output is correct
85 Correct 92 ms 16324 KB Output is correct
86 Correct 121 ms 13884 KB Output is correct
87 Correct 174 ms 14020 KB Output is correct
88 Correct 229 ms 15044 KB Output is correct
89 Correct 154 ms 14016 KB Output is correct
90 Correct 177 ms 15820 KB Output is correct
91 Correct 122 ms 11212 KB Output is correct
92 Correct 189 ms 14800 KB Output is correct
93 Correct 228 ms 16580 KB Output is correct
94 Correct 130 ms 16572 KB Output is correct
95 Correct 173 ms 21176 KB Output is correct
96 Correct 126 ms 19644 KB Output is correct
97 Correct 144 ms 16576 KB Output is correct
98 Correct 151 ms 16772 KB Output is correct
99 Correct 161 ms 15912 KB Output is correct
100 Correct 215 ms 20416 KB Output is correct
101 Correct 152 ms 16060 KB Output is correct
102 Correct 192 ms 17980 KB Output is correct
103 Correct 211 ms 20424 KB Output is correct
104 Correct 154 ms 15560 KB Output is correct
105 Correct 221 ms 17288 KB Output is correct
106 Correct 247 ms 19136 KB Output is correct
107 Correct 101 ms 20668 KB Output is correct
108 Correct 138 ms 16572 KB Output is correct
109 Correct 131 ms 17356 KB Output is correct
110 Correct 135 ms 16576 KB Output is correct
111 Correct 132 ms 17252 KB Output is correct
112 Correct 131 ms 16520 KB Output is correct
113 Correct 134 ms 17148 KB Output is correct
114 Correct 130 ms 16832 KB Output is correct
115 Correct 137 ms 17388 KB Output is correct
116 Correct 130 ms 16572 KB Output is correct