# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
906119 |
2024-01-13T14:16:23 Z |
sunwukong123 |
Joker (BOI20_joker) |
C++14 |
|
2000 ms |
43968 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const int MAXN = 200005;
const int inf=1000000500ll;
const long long oo =1000000000000000500ll;
const int MOD = (int)1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> pi;
int n,m,q;
pi A[MAXN];
struct ufds_{
int p[MAXN],dist[MAXN];
vector<array<int,4>>rollback;
int TIME=0;
bool nonbi=0;
ufds_(){
iota(p,p+MAXN,0);
}
pi find(int x){
if(x==p[x])return {x,dist[x]};
else{
rollback.push_back({TIME,x,p[x],dist[x]});
pi np=find(p[x]);
dist[x]^=np.second;
p[x]=np.first;
return {p[x],dist[x]};
}
}
void merge(int x, int y){
++TIME;
int distx=dist[x];
int disty=dist[y];
if(find(x) == find(y)){
if((dist[x] ^ dist[y]) == 0){
rollback.push_back({TIME,-1,nonbi,nonbi});
nonbi=1;
} else {
}
return;
}
x=find(x).first;
rollback.push_back({TIME,x,p[x],dist[x]});
dist[x]=distx^disty^1;
p[x]=find(y).first;
}
void rb(int dt){
int tt=TIME-dt;
while(rollback.size() && rollback.back()[0]>tt){
array<int,4>cur=rollback.back();rollback.pop_back();
if(cur[1] == -1){
nonbi=cur[2];
} else{
p[cur[1]]=cur[2];
dist[cur[1]]=cur[3];
}
}
TIME-=dt;
}
}ufds;
int ans[MAXN];
void dnc(int s, int e, int l, int r){
if(s>e)return;
int m=(s+e)/2;
debug(m);
for(int i=s;i<=m;i++){
ufds.merge(A[i].first,A[i].second);
debug(i,ufds.nonbi);
}
for(int i=r;i>=l;i--){
ufds.merge(A[i].first,A[i].second);
debug(i,ufds.nonbi);
if(ufds.nonbi){
ans[m]=i;
break;
}
}
ufds.rb(r-ans[m]+1);
if(s!=e){
dnc(m+1,e,ans[m],r);
}
ufds.rb(m-s+1);
if(s!=e){
for(int i=r;i>=ans[m];i--){
ufds.merge(A[i].first,A[i].second);
}
dnc(s,m-1,l,ans[m]);
ufds.rb(r-ans[m]+1);
}
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m>>q;
A[0].first=n+1;
A[0].second=n+2;
A[m+1].first=n+1;
A[m+1].second=n+2;
for(int i=1;i<=m;i++)cin>>A[i].first>>A[i].second;
dnc(0,m+1,0,m+1);
for(int i=0;i<=m+1;i++){
debug(i,ans[i]);
}
while(q--){
int l,r;cin>>l>>r;
if(ans[l-1]>r)cout<<"YES\n";
else cout<<"NO\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Execution timed out |
2032 ms |
43968 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |