QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#603377 | #9170. Cycle Game | peter | WA | 11ms | 57020kb | C++14 | 2.4kb | 2024-10-01 16:15:14 | 2024-10-01 16:15:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int maxn=5e5+5;
int dx[]={-1,-1,-1,0,0,1,1,1},dy[]={-1,0,1,-1,1,-1,0,1};
int fa[maxn],sz[maxn],n,m,q;
vector<pii> tr[maxn<<2];
map<pii,int> mp;
int st[maxn],top=0;
pii que[maxn];
int find(int x){
if(fa[x]==x) return x;
return find(fa[x]);
}
void merge(int x,int y){
x=find(x);
y=find(y);
if(x==y) return;
if(sz[x]>sz[y]) swap(x,y);
fa[x]=y;
sz[y]+=sz[x];
st[++top]=x;
}
void del(int lst){
while(top>lst){
int x=st[top];
top--;
sz[fa[x]]-=sz[x];
fa[x]=x;
}
}
int getid(int x,int y){
return (x-1)*(m+2)+y;
}
bool bk[maxn];
void update(int now,int l,int r,int ql,int qr,pii x){
if(ql>qr) return;
if(ql<=l&&qr>=r){
tr[now].push_back(x);
return;
}
int mid=(l+r)>>1;
if(ql<=mid) update(now<<1,l,mid,ql,qr,x);
if(qr>mid) update(now<<1|1,mid+1,r,ql,qr,x);
}
void dfs(int now,int l,int r){
int lst=top;
for(pii x : tr[now]) merge(x.first,x.second);
if(l==r){
int x=que[l].first,y=que[l].second,tt=0;
bool flag=0;
for(int j=0;j<8;j++){
int nx=x+dx[j],ny=y+dy[j];
if(!bk[getid(nx,ny)]){
if(!tt) tt=find(getid(nx,ny));
else if(tt!=find(getid(nx,ny))){
flag=1;
break;
}
}
}
if(flag){
for(int j=0;j<8;j++){
int nx=x+dx[j],ny=y+dy[j];
pii tmp=make_pair(getid(x,y),getid(nx,ny));
if(mp[tmp]==l) update(1,1,q,l+1,n,tmp);
else update(1,1,q,l+1,mp[tmp]-1,tmp);
}
putchar('0');
}else{
bk[getid(x,y)]=1;
putchar('1');
}
del(lst);
return;
}
int mid=(l+r)>>1;
dfs(now<<1,l,mid);
dfs(now<<1|1,mid+1,r);
del(lst);
}
int main(){
scanf("%d %d %d",&n,&m,&q);
for(int i=1;i<=q;i++){
int x,y;
scanf("%d %d",&x,&y);
for(int j=0;j<8;j++){
int nx=x+dx[j],ny=y+dy[j];
pii t1=make_pair(getid(x,y),getid(nx,ny)),t2=make_pair(getid(nx,ny),getid(x,y));
if(mp.find(t1)==mp.end()) update(1,1,q,1,i-1,t1);
mp[t1]=mp[t2]=i;
}
bk[getid(x,y)]=1;
que[i]=make_pair(x,y);
}
for(int i=0;i<=(n+1)*(m+1);i++) fa[i]=i;
for(int x=0;x<=n+1;x++){
for(int y=0;y<=m+1;y++){
for(int k=0;k<8;k++){
int nx=x+dx[k],ny=y+dy[k];
if(nx<0||nx>n+1||ny<0||ny>m+1) continue;
if(bk[getid(x,y)]||bk[getid(nx,ny)]) continue;
merge(getid(x,y),getid(nx,ny));
}
}
}
for(int i=1;i<=q;i++) bk[getid(que[i].first,que[i].second)]=0;
dfs(1,1,q);
puts("");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 10ms
memory: 54912kb
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: 4ms
memory: 54848kb
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: 11ms
memory: 54844kb
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: 11ms
memory: 57020kb
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: 9ms
memory: 56900kb
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: 8ms
memory: 54800kb
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: 10ms
memory: 55056kb
input:
1 4 1 1 2
output:
1
result:
ok "1"
Test #8:
score: -100
Wrong Answer
time: 4ms
memory: 56884kb
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:
1111111111111111111111111111111111111111111110011111101010001101111
result:
wrong answer 1st words differ - expected: '111111111111111111111111111111...1111111110010101101000101101101', found: '111111111111111111111111111111...1111111110011111101010001101111'