QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#588358 | #9170. Cycle Game | yhddd | WA | 2ms | 10040kb | C++20 | 3.5kb | 2024-09-25 09:58:47 | 2024-09-25 09:58:49 |
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 pos(int id){
int u=(id-1)/m+1,v=id-(u-1)*m;
return {u,v};
}
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){
if(siz[fd(n*m+1)]!=num-1){
ans[l]=0;
int i=pos(l).fi,j=pos(l).se;
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)],{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)});
}
}
}
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++){
int u=read(),v=read();
vis[id(u,v)]=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();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 10040kb
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: 10036kb
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: 9992kb
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: 0ms
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: 0ms
memory: 9908kb
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: 9992kb
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: 10036kb
input:
1 4 1 1 2
output:
1
result:
ok "1"
Test #8:
score: -100
Wrong Answer
time: 2ms
memory: 9932kb
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:
1111111111111111111111111111111111111111111110000000000000000000000
result:
wrong answer 1st words differ - expected: '111111111111111111111111111111...1111111110010101101000101101101', found: '111111111111111111111111111111...1111111110000000000000000000000'