Codeforces Round#614--C题--思维

思路:新的状态可不可行与上一个状态可不可行和新坐标的更新有关,循环看新加入的点是否构成墙,再看墙数是否大于0,大于0就可不行

#include <cstdio>
#include <set>
using namespace std;
int n,q;
const int N = 3e5;
bool st[N];
int cnt;
void update(int x){
	if(st[x]){
		if(x > n){
			if(st[x-n]) cnt++;
			if(st[x-n+1]) cnt++;
			if(st[x-n-1]) cnt++;
		}else{
			if(st[x+n]) cnt++;
			if(st[x+n+1]) cnt++;
			if(st[x+n-1]) cnt++;
		}
	}else{
		if(x > n){
			if(st[x-n]) cnt--;
			if(st[x-n+1]) cnt--;
			if(st[x-n-1]) cnt--;
		}else{
			if(st[x+n]) cnt--;
			if(st[x+n+1]) cnt--;
			if(st[x+n-1]) cnt--;
		}
	}
}
int main(){
	scanf("%d%d",&n,&q);
	int r,c;
	cnt = 0;//墙的数量 
	for(int i = 0;i < q;i++){
		scanf("%d%d",&r,&c);
		int x = (r-1)*n+c;
		if(st[x]){
			st[x] = 0;
		}else{
			st[x] = 1;
		}
		update(x);
		if(cnt > 0) puts("No");
		else puts("Yes"); 
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值