NEKO's Maze Game(思维)

3R2 as DJ Mashiro - Happiness Breeze
Ice - DJ Mashiro is dead or alive
NEKO#ΦωΦ has just got a new maze game on her PC!

The game’s main puzzle is a maze, in the forms of a 2×n2×n rectangle grid. NEKO’s task is to lead a Nekomimi girl from cell (1,1)(1,1) to the gate at (2,n)(2,n) and escape the maze. The girl can only move between cells sharing a common side.

However, at some moments during the game, some cells may change their state: either from normal ground to lava (which forbids movement into that cell), or vice versa (which makes that cell passable again). Initially all cells are of the ground type.

After hours of streaming, NEKO finally figured out there are only qq such moments: the ii-th moment toggles the state of cell (ri,ci)(ri,ci) (either from ground to lava or vice versa).

Knowing this, NEKO wonders, after each of the qq moments, whether it is still possible to move from cell (1,1)(1,1) to cell (2,n)(2,n) without going through any lava cells.

Although NEKO is a great streamer and gamer, she still can’t get through quizzes and problems requiring large amount of Brain Power. Can you help her?

Input
The first line contains integers nn, qq (2≤n≤1052≤n≤105, 1≤q≤1051≤q≤105).

The ii-th of qq following lines contains two integers riri, cici (1≤ri≤21≤ri≤2, 1≤ci≤n1≤ci≤n), denoting the coordinates of the cell to be flipped at the ii-th moment.

It is guaranteed that cells (1,1)(1,1) and (2,n)(2,n) never appear in the query list.

Output
For each moment, if it is possible to travel from cell (1,1)(1,1) to cell (2,n)(2,n), print “Yes”, otherwise print “No”. There should be exactly qq answers, one after every update.

You can print the words in any case (either lowercase, uppercase or mixed).

Example
Input
5 5
2 3
1 4
2 4
2 3
1 4
Output
Yes
No
No
No
Yes
Note
We’ll crack down the example test here:

After the first query, the girl still able to reach the goal. One of the shortest path ways should be: (1,1)→(1,2)→(1,3)→(1,4)→(1,5)→(2,5)(1,1)→(1,2)→(1,3)→(1,4)→(1,5)→(2,5).
After the second query, it’s impossible to move to the goal, since the farthest cell she could reach is (1,3)(1,3).
After the fourth query, the (2,3)(2,3) is not blocked, but now all the 44-th column is blocked, so she still can’t reach the goal.
After the fifth query, the column barrier has been lifted, thus she can go to the final goal again.
思路:对于每一个格子,我们考虑的是它的通或者不通,与哪些格子组合起来会对结果产生影响。
在这里插入图片描述
就是这两种情况。如果这个格子变为不通的了,如果其他三个格子有一个不通的,就绝对到达不了。如果这个格子变为通的了,就要消除它之前不通带来的影响。直到整体的影响变为0,才可以通。
代码如下:

#include<bits/stdc++.h>
using namespace std;

const int maxx=1e5+100;
struct node{
	int x,y;
}p[maxx];
int vis[3][maxx];
int n,q;

int main()
{
	scanf("%d%d",&n,&q);
	int x,y;
	int ans=0;
	for(int i=1;i<=q;i++) 
	{
		scanf("%d%d",&x,&y);
		if(vis[x][y]==0)
		{
			vis[x][y]=1;
			if(vis[3-x][y]) ans++;
			if(vis[3-x][y+1]&&y+1<=n) ans++;
			if(vis[3-x][y-1]&&y-1>=1) ans++;
		}
		else 
		{
			vis[x][y]=0;
			if(vis[3-x][y]) ans--;
			if(vis[3-x][y+1]&&y+1<=n) ans--;
			if(vis[3-x][y-1]&&y-1>=1) ans--;
		}
		if(!ans) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

努力加油a啊,(o)/~

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值