QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#747105#9170. Cycle Gameucup-team134WA 0ms4040kbC++143.0kb2024-11-14 16:21:342024-11-14 16:21:34

Judging History

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

  • [2024-11-14 16:21:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4040kb
  • [2024-11-14 16:21:34]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128

using namespace std;

mt19937 rng(time(NULL));

int main()
{
	// 8:50
	ios;
	int n,m,k;
	cin>>n>>m>>k;
	vector<pair<int,int>> o;
	for(int i=0;i<k;i++){
		int x,y;
		cin>>x>>y;
		o.pb({x-1,y-1});
	}
	vector<int> dx={1,1,1,0,-1,-1,-1,0},dy={1,0,-1,-1,-1,0,1,1};
	vector<int> par(n*m+1),siz(n*m+1);
	int cntComp=0;
	vector<vector<bool>> on(n,vector<bool>(m));
	vector<vector<int>> cnt(n,vector<int>(m));
	int cnt8=0;
	vector<pair<int,vector<pair<int,int>>>> back;
	auto inside=[&](int x,int y){
		return x>=0&&x<n&&y>=0&&y<m;
	};
	auto onBorder=[&](int x,int y){
		return x==0||x==n-1||y==0||y==m-1;
	};
	int cntOn=0;
	auto add=[&](int x,int y){
		on[x][y]=1;
		cntOn++;
		for(int kk=0;kk<8;kk++){
			int xx=x+dx[kk],yy=y+dy[kk];
			if(inside(xx,yy)){
				cnt[xx][yy]++;
				if(cnt[xx][yy]==8)cnt8++;
			}
		}
	};
	auto rem=[&](int x,int y){
		on[x][y]=0;
		cntOn--;
		for(int kk=0;kk<8;kk++){
			int xx=x+dx[kk],yy=y+dy[kk];
			if(inside(xx,yy)){
				if(cnt[xx][yy]==8)cnt8--;
				cnt[xx][yy]--;
			}
		}
	};
	function<int(int)> find=[&](int tr){
		return tr==par[tr]?tr:find(par[tr]);
	};
	auto snap=[&](){
		back.pb({cntComp,{}});
	};
	auto reverse=[&](){
		for(int i=sz(back.back().s)-1;i>=0;i--){
			int a=back.back().s[i].f,p=back.back().s[i].s;
			siz[par[a]]-=siz[a];
			par[a]=p;
		}
		cntComp=back.back().f;
		back.pop_back();
	};
	auto merge=[&](int a,int b){
		a=find(a);
		b=find(b);
		if(a==b)return;
		if(siz[a]>siz[b])swap(a,b);
		if(sz(back))
			back.back().s.pb({a,par[a]});
		par[a]=b;
		siz[b]+=siz[a];
		cntComp--;
	};
	auto remD=[&](int x,int y,bool init){
		assert(!on[x][y]);
		if(onBorder(x,y)){
			merge(x*m+y,n*m);
		}
		int t=4;
		if(!init)t=8;
		for(int kk=0;kk<t;kk++){
			int xx=x+dx[kk],yy=y+dy[kk];
			if(inside(xx,yy)&&!on[xx][yy]){
				merge(x*m+y,xx*m+yy);
			}
		}
	};
	auto okState=[&](){
		return cntComp-cntOn==1&&cnt8==0;
	};
	iota(all(par),0);
	fill(all(siz),1);
	cntComp=sz(par);
	for(auto p:o){
		add(p.f,p.s);
	}
	for(int x=0;x<n;x++){
		for(int y=0;y<m;y++){
			if(!on[x][y]){
				remD(x,y,1);
			}
		}
	}
	for(int i=0;i<n*m;i++){
		par[i]=find(i);
	}
	
	vector<bool> ok(k,1);
	function<void(int,int)> solve=[&](int l,int r){
		if(okState())return;
		if(l==r){
			ok[l]=0;
			return;
		}
		int m=(l+r)>>1;
		snap();
		for(int i=m+1;i<=r;i++){
			rem(o[i].f,o[i].s);
			remD(o[i].f,o[i].s,0);
		}
		solve(l,m);
		reverse();
		for(int i=m+1;i<=r;i++){
			add(o[i].f,o[i].s);
		}
		for(int i=l;i<=m;i++){
			if(!ok[i]){
				rem(o[i].f,o[i].s);
				remD(o[i].f,o[i].s,0);
			}
		}
		solve(m+1,r);
	};
	solve(0,k-1);
	for(int i=0;i<k;i++){
		printf(ok[i]?"1":"0");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3732kb

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

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

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

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

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

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

input:

1 4 1
1 2

output:

1

result:

ok "1"

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 4040kb

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'