QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#513909#9170. Cycle Gameucup-team3510#WA 244ms92668kbC++203.4kb2024-08-10 20:42:372024-08-10 20:42:38

Judging History

你现在查看的是最新测评结果

  • [2024-08-10 20:42:38]
  • 评测
  • 测评结果:WA
  • 用时:244ms
  • 内存:92668kb
  • [2024-08-10 20:42:37]
  • 提交

answer

#include <bits/stdc++.h>
#define N 300011
#define ID(i,j) (((i)-1)*m+(j))
#define pii pair<int,int>
#define s1 first
#define s2 second
using namespace std;
int n,m,k;
vector<pair<int*,int> > v;
int fa[N],siz[N];
int C,cnt0;
int get(int a){return fa[a]==a?a:get(fa[a]);}
void merge(int a,int b)
{
	a=get(a);b=get(b);
	if(a==b)return;
	++C;//printf("merge(%d,%d)\n",a,b);
	if(siz[a]<siz[b])swap(a,b);
	v.push_back({siz+a,siz[a]});
	siz[a]+=siz[b];
	v.push_back({fa+b,fa[b]});
	fa[b]=a;
}
vector<pii > ve[N*4];
void ins(int l,int r,int a,int b,int L,int R,int x)
{//printf("ins([%d,%d],%d-%d,[%d,%d],%d)\n",l,r,a,b,L,R,x);
	if(l>r)return;
	if(l<=L&&R<=r){ve[x].push_back({a,b});return;}
	if(l<=L+R>>1)ins(l,r,a,b,L,L+R>>1,x<<1);if(r>L+R>>1)ins(l,r,a,b,(L+R>>1)+1,R,x<<1|1);
}
bool a[N];
bool check(int x,int y)
{
	for(int _=0;_<3;++_)for(int __=0;__<3;++__)if(!a[ID(x+_,y+__)])return 0;return 1;
}
int qx[N],qy[N];
int dxy[8][2]={{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1}};
int tim[N],ans[N];
void dfs(int L,int R,int x)
{//printf("-----------------------dfs([%d,%d],%d) C:%d\n",L,R,x,C);
	int tmdn=v.size(),tC=C;//printf("v.size():%d\n",(int)v.size());
	for(pii y:ve[x])merge(y.s1,y.s2);
	ve[x].clear();ve[x].shrink_to_fit();
	if(L==R)
	{//printf("-----------[%d,%d]\n",L,R);
		// printf("C:%d cnt0:%d\n",C,cnt0);
		// printf("get0:%d\n",get(0));
		// for(int i=1;i<=n;++i)
		// {
		// 	for(int j=1;j<=m;++j)printf("%d ",get(ID(i,j)));putchar(10);
		// }
		bool ok=1;
		a[ID(qx[L],qy[L])]=1;
		if(C!=(cnt0-1)-1)ok=0;
		else
		{
			for(int _=0;_<3&&qx[L]-_>0;++_)
			{
				for(int __=0;__<3&&qy[L]-__>0;++__)if(check(qx[L]-_,qy[L]-__)){ok=0;break;}
				if(!ok)break;
			}
		}
		ans[L]=ok;
		if(!ok)
		{
			a[ID(qx[L],qy[L])]=0;
			for(int _=0;_<8;++_)
			{
				int nx=qx[L]+dxy[_][0],ny=qy[L]+dxy[_][1];
				int idx=0;
				if(nx<=0||nx>n||ny<=0||ny>m)idx=0;
				else if(a[ID(nx,ny)])continue;
				else idx=ID(nx,ny);
				if(tim[idx]>L)ins(L+1,tim[idx]-1,ID(qx[L],qy[L]),idx,1,k,1);
				else ins(L+1,k,ID(qx[L],qy[L]),idx,1,k,1);
			}
		}
		else --cnt0,a[ID(qx[L],qy[L])]=1;
		while(tmdn<v.size())*v.back().s1=v.back().s2,v.pop_back();C=tC;//printf("new C:%d\n",C);
		return;
	}//printf("ntbom\n");
	dfs(L,L+R>>1,x<<1);
	dfs((L+R>>1)+1,R,x<<1|1);//printf("tv.size():%d tmdn:%d\n",(int)v.size());
	while(tmdn<v.size())*v.back().s1=v.back().s2,v.pop_back();C=tC;
		// for(int i=1;i<=n;++i)
		// {
		// 	for(int j=1;j<=m;++j)printf("%d ",get(ID(i,j)));putchar(10);
		// }
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);cnt0=n*m+1;
	for(int i=0;i<=n*m;++i)fa[i]=i,siz[i]=1;
	for(int i=1;i<=k;++i)scanf("%d%d",qx+i,qy+i),tim[ID(qx[i],qy[i])]=i;
	for(int i=0;i<=n*m;++i)if(!tim[i])tim[i]=k+1;
	// printf("tim0:%d\n",tim[0]);
	// printf("tim:\n");
	// for(int i=1;i<=n;++i){for(int j=1;j<=m;++j)printf("%d ",tim[ID(i,j)]);putchar(10);}
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			for(int _=0;_<8;++_)
			{
				int nx=i+dxy[_][0],ny=j+dxy[_][1];
				int idx=0;
				if(nx<=0||nx>n||ny<=0||ny>m)idx=0;
				else if(a[ID(nx,ny)])continue;
				else idx=ID(nx,ny);
				if(idx&&_>=4)continue;
				// printf("i:%d j:%d nx:%d ny:%d idx:%d tim:[%d,%d]\n",i,j,nx,ny,idx,1,min(tim[idx],tim[ID(i,j)])-1);
				ins(1,min(tim[idx],tim[ID(i,j)])-1,ID(i,j),idx,1,k,1);
			}
		}
	}
	dfs(1,k,1);
	for(int i=1;i<=k;++i)putchar(ans[i]+'0');putchar(10);
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 9916kb

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: 0ms
memory: 9844kb

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: 9820kb

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: 9988kb

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: 9720kb

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: 0ms
memory: 9724kb

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: 2ms
memory: 9844kb

input:

1 4 1
1 2

output:

1

result:

ok "1"

Test #8:

score: 0
Accepted
time: 2ms
memory: 7936kb

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: 2ms
memory: 9980kb

input:

3 10 3
3 9
2 5
2 7

output:

111

result:

ok "111"

Test #10:

score: 0
Accepted
time: 57ms
memory: 53852kb

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...

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

ok "111111111111111111111111111111...1111111111111111111111111111111"

Test #11:

score: -100
Wrong Answer
time: 244ms
memory: 92668kb

input:

1 167058 126088
1 15282
1 63796
1 77270
1 88793
1 42787
1 129851
1 34468
1 74525
1 121105
1 157182
1 92736
1 102044
1 11284
1 23439
1 142720
1 128610
1 27437
1 105575
1 130827
1 152824
1 76358
1 152954
1 65509
1 139802
1 66299
1 108943
1 140446
1 112411
1 95814
1 115750
1 9667
1 55383
1 89323
1 6734...

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st words differ - expected: '111111111111111111111111111111...1111111111111111111111111111111', found: '111111111111111111111111111111...1111111111111111111111111111111'