QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#588416 | #9170. Cycle Game | yhddd | RE | 3ms | 14148kb | C++20 | 4.0kb | 2024-09-25 10:46:44 | 2024-09-25 11:42:13 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=200010;
const int inf=1e18;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
return x*f;
}
bool Mbe;
int n,m,k;
int vis[maxn],ans[maxn];
int id(int u,int v){return (u-1)*m+v;}
pii a[maxn];
int fx[8][2]={{1,1},{1,0},{1,-1},{0,1},{0,-1},{-1,1},{-1,0},{-1,-1}};
int f[maxn],siz[maxn];
int fd(int x){
if(f[x]==x)return x;
return fd(f[x]);
}
int st[maxn][2],tp;
void merge(int u,int v){
u=fd(u),v=fd(v);
if(u==v)return ;
if(siz[u]>siz[v])swap(u,v);
st[++tp][0]=u,st[tp][1]=siz[u];
f[u]=v,siz[v]+=siz[u];
}
void del(){
siz[f[st[tp][0]]]-=st[tp][1];
f[st[tp][0]]=st[tp][0];
tp--;
}
#define mid (l+r>>1)
#define ls nd<<1
#define rs nd<<1|1
vector<pii> tree[maxn<<2];
void updata(int nd,int l,int r,int ql,int qr,pii w){
// if(nd==1)cout<<w.fi<<" "<<w.se<<" "<<ql<<" "<<qr<<"\n";
if(ql>qr)return ;
if(l>=ql&&r<=qr){tree[nd].pb(w);return ;}
if(ql<=mid)updata(ls,l,mid,ql,qr,w);
if(qr>mid)updata(rs,mid+1,r,ql,qr,w);
}
int num;
void dfs(int nd,int l,int r){
int lst=tp;
for(pii p:tree[nd])merge(p.fi,p.se);
// cout<<l<<" "<<r<<" "<<siz[fd(n*m+1)]<<"\n";
if(l==r){
int i=a[l].fi,j=a[l].se;ans[l]=1;
bool fl=1;
for(int o=0;o<8;o++){
int nx=i+fx[o][0],ny=j+fx[o][1];
if(nx<=0||ny<=0||nx>n||ny>m||!ans[vis[id(nx,ny)]])continue;
bool fl1=0;
for(int oo=0;oo<8;oo++){
int nnx=nx+fx[oo][0],nny=ny+fx[oo][1];
if(nnx<=0||nny<=0||nnx>n||nny>m||ans[vis[id(nnx,nny)]])continue;
fl1=1;
}
if(nx==1||nx==n||ny==1||ny==m)fl1=1;
fl&=fl1;
}
if(siz[fd(n*m+1)]!=num-1||!fl){
ans[l]=0;
// cout<<l<<" "<<i<<" "<<j<<" "<<siz[fd(n*m+1)]<<" "<<num<<" "<<fd(id(1,6))<<"\n";
for(int o=0;o<8;o++){
int nx=i+fx[o][0],ny=j+fx[o][1];
if(nx<=0||ny<=0||nx>n||ny>m)continue;
if(!vis[id(nx,ny)]){
updata(1,1,k,l+1,k,{id(i,j),id(nx,ny)});
}
else if(vis[id(i,j)]<vis[id(nx,ny)]){
updata(1,1,k,l+1,vis[id(nx,ny)]-1,{id(i,j),id(nx,ny)});
}
else if(!ans[vis[id(nx,ny)]]){
updata(1,1,k,l+1,k,{id(i,j),id(nx,ny)});
}
}
if(i==1||i==n||j==1||j==m)updata(1,1,k,l+1,k,{id(i,j),n*m+1});
}
else ans[l]=1,num--;
}
else dfs(ls,l,mid),dfs(rs,mid+1,r);
while(tp>lst)del();
}
void work(){
n=read();m=read();k=read();
for(int i=1;i<=k;i++)a[i]={read(),read()},vis[id(a[i].fi,a[i].se)]=i;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)if(vis[id(i,j)]){
for(int o=0;o<8;o++){
int nx=i+fx[o][0],ny=j+fx[o][1];
if(nx<=0||ny<=0||nx>n||ny>m)continue;
if(!vis[id(nx,ny)]){
updata(1,1,k,1,vis[id(i,j)]-1,{id(i,j),id(nx,ny)});
}
if(vis[id(i,j)]<vis[id(nx,ny)]){
updata(1,1,k,1,vis[id(i,j)]-1,{id(i,j),id(nx,ny)});
}
}
if(i==1||i==n||j==1||j==m)updata(1,1,k,1,vis[id(i,j)]-1,{id(i,j),n*m+1});
}
}
for(int i=1;i<=n*m+1;i++)f[i]=i,siz[i]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)if(!vis[id(i,j)]){
for(int o=0;o<8;o++){
int nx=i+fx[o][0],ny=j+fx[o][1];
if(nx<=0||ny<=0||nx>n||ny>m)continue;
if(!vis[id(nx,ny)])merge(id(i,j),id(nx,ny));
}
}
}
for(int i=1;i<=n;i++){
if(!vis[id(i,1)])merge(n*m+1,id(i,1));
if(!vis[id(i,m)])merge(n*m+1,id(i,m));
}
for(int j=2;j<m;j++){
if(!vis[id(1,j)])merge(n*m+1,id(1,j));
if(!vis[id(n,j)])merge(n*m+1,id(n,j));
}
// cout<<siz[fd(1)]<<"\n";
num=n*m+1;dfs(1,1,k);
for(int i=1;i<=k;i++)printf("%lld",ans[i]);
}
// \
444
bool Med;
int T;
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
T=1;
while(T--)work();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 12052kb
input:
4 3 7 2 1 2 2 2 3 3 1 3 2 4 1 4 2
output:
1111111
result:
ok "1111111"
Test #2:
score: 0
Accepted
time: 2ms
memory: 9916kb
input:
3 3 8 1 1 1 2 1 3 2 3 3 3 3 2 3 1 2 1
output:
11111110
result:
ok "11111110"
Test #3:
score: 0
Accepted
time: 2ms
memory: 14028kb
input:
10 10 7 9 1 6 6 3 8 8 7 5 10 1 7 1 2
output:
1111111
result:
ok "1111111"
Test #4:
score: 0
Accepted
time: 2ms
memory: 10008kb
input:
9 10 50 1 9 1 6 2 3 3 1 7 4 9 4 1 3 2 5 9 2 7 9 5 6 8 10 9 5 5 5 4 10 9 7 5 9 3 2 4 5 1 1 4 7 3 6 2 8 4 3 8 6 5 10 4 8 5 4 7 2 9 6 4 2 7 8 5 2 3 5 9 1 6 1 1 5 9 9 5 8 6 3 8 8 8 4 7 7 7 1 3 7 2 2 3 10 6 9 8 3 7 6
output:
11111111111111111111111111111111111111111111111111
result:
ok "11111111111111111111111111111111111111111111111111"
Test #5:
score: 0
Accepted
time: 2ms
memory: 14148kb
input:
3 5 11 1 5 2 4 1 2 1 3 3 3 3 1 3 4 2 3 1 4 2 1 2 5
output:
11111111111
result:
ok "11111111111"
Test #6:
score: 0
Accepted
time: 2ms
memory: 9988kb
input:
7 9 12 7 3 2 3 6 2 2 2 4 2 2 8 5 7 4 4 6 8 2 7 7 2 1 9
output:
111111111111
result:
ok "111111111111"
Test #7:
score: 0
Accepted
time: 0ms
memory: 14088kb
input:
1 4 1 1 2
output:
1
result:
ok "1"
Test #8:
score: 0
Accepted
time: 2ms
memory: 12036kb
input:
9 8 67 5 5 8 3 9 5 7 4 5 1 9 3 4 2 2 5 1 7 7 8 7 2 8 5 6 1 8 8 4 4 5 4 1 5 3 4 6 7 2 3 3 7 5 7 2 4 2 7 1 3 7 3 2 8 6 6 6 2 6 3 7 5 9 6 7 6 3 6 1 1 6 4 3 1 5 3 8 7 2 1 4 1 8 4 8 6 3 5 5 8 1 6 1 2 4 6 9 4 1 4 3 3 4 8 8 1 4 7 9 8 3 8 6 5 6 8 3 2 2 2 7 1 9 2 4 3 1 8 4 5 8 2 7 7
output:
1111111111111111111111111111111111111111111110010101101000101101101
result:
ok "111111111111111111111111111111...1111111110010101101000101101101"
Test #9:
score: 0
Accepted
time: 0ms
memory: 11960kb
input:
3 10 3 3 9 2 5 2 7
output:
111
result:
ok "111"
Test #10:
score: -100
Runtime Error
input:
222212 1 21562 105762 1 167947 1 127551 1 117618 1 174844 1 139867 1 156729 1 30554 1 54488 1 151832 1 132914 1 109432 1 212091 1 136499 1 17818 1 48806 1 95752 1 66607 1 39930 1 23054 1 160823 1 169054 1 96680 1 150677 1 52895 1 93103 1 118079 1 79155 1 194811 1 141874 1 138763 1 2600 1 121471 1 17...