# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
990319 |
2024-05-30T07:58:42 Z |
imarn |
Joker (BOI20_joker) |
C++14 |
|
2000 ms |
12852 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;
bool ok=0;
void rollback(int x){
while(st.size()>x){
if(st.top().f==-1){
st.pop();ok=0;continue;
}
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 uni2(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 uni(int a,int b){
uni2(a,b+n);uni2(a+n,b);
if(get(a)==get(a+n)||get(b)==get(b+n))ok=1,st.push({-1,-1});
}
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);
}int pv2=st.size();
for(int i=r2;i>=max(l2,md);i--){
if(ok){md2=i;break;}
uni(edge[i-1].f,edge[i-1].s);
}if(md2==-1)md2=md-1;
dp[md]=md2;rollback(pv2);
uni(edge[md-1].f,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);
}
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);
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:17: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]
17 | while(st.size()>x){
| ~~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Incorrect |
1 ms |
4584 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Incorrect |
1 ms |
4584 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Execution timed out |
2066 ms |
12852 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Incorrect |
1 ms |
4584 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Incorrect |
1 ms |
4584 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Incorrect |
1 ms |
4584 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |