题目链接: C. NEKO’s Maze Game

time limit per test:1.5 seconds memory limit per test:256 megabytes inputstandard input outputstandard output

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×n rectangle grid. NEKO’s task is to lead a Nekomimi girl from cell (1,1) to the gate at (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 q such moments: the i-th moment toggles the state of cell (ri,ci) (either from ground to lava or vice versa).

Knowing this, NEKO wonders, after each of the q moments, whether it is still possible to move from cell (1,1) to cell (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 n, q (2≤n≤105, 1≤q≤105).

The i-th of q following lines contains two integers ri, ci (1≤ri≤2, 1≤ci≤n), denoting the coordinates of the cell to be flipped at the i-th moment.

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

Output
For each moment, if it is possible to travel from cell (1,1) to cell (2,n), print “Yes”, otherwise print “No”. There should be exactly q answers, one after every update.
You can print the words in any case (either lowercase, uppercase or mixed).

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).
After the second query, it’s impossible to move to the goal, since the farthest cell she could reach is (1,3).
After the fourth query, the (2,3) is not blocked, but now all the 4-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.

题目大意

给你一个2xN的表格,一共有q次查询,每次查询前会有一个表格变成岩浆不能走,或者从岩浆变回了可以总,问你能否从1 1这个表格走到2 n这个位置,可以的话就输出“Yse”,否则就是“No”;

解题思路

表格的变换我们可以用位运算 异或 来处理,问题是我们怎么判断这次变化后是否可行呢?经过画图的多次尝试,我们发现如果这次不行,那么肯定至少有一列都是岩浆或者至少有一个对角线的位置是岩浆,因此我们可以运用类似前缀和的思想,每次统计以变化位置为中心的连着三个对立位置如果该位置是岩浆,就统计对面三个位置有几个熔浆,如果是可以走,那就减去前面位置有几块熔浆如果结果为零那说明可以走,因为没有一块岩浆,如果不唯一就不行,这里为什么呢?你想呀,如果你这个位置查询的时候是0,可以走的说明什么?说明之前他是1不能走,既然之前不能走,那之前的ans肯定包含不能走时的转态,如果上一次这三个位置都是0,ans加的是0,这次减得也是零对结果没影响,如果上次这三个位置是1呢?说明上次ans加了三个1,这次刚好减去这里很巧妙的运用了位运算和前缀和的思想,真的太巧了,膜拜大神们呀!

代码

#include<bits/stdc++.h>
using namespace std;
const int mx=1e5+10;
int a[2][mx];int main()
{int q,ans=0,n;cin>>n>>q;int x,y;while(q--){cin>>x>>y;x--;//x--,方便以后的 ^ 运算 a[x][y]^=1;//改变这个位置的状态 int m=a[x][y]*2-1;//如果是 0 就是可以走,那结果就要减,1的话加 ans+=m*(a[x^1][y-1]+a[x^1][y]+a[x^1][y+1]);//进行ans的累加 if(ans==0)cout<<"Yes"<<'\n';else cout<<"No"<<'\n';}return 0;
}

C. NEKO's Maze Game相关推荐

  1. NEKO's Maze Game(思维)

    3R2 as DJ Mashiro - Happiness Breeze Ice - DJ Mashiro is dead or alive NEKO#ΦωΦ has just got a new m ...

  2. CodeForces - 1293C NEKO's Maze Game(思维,水题)

    题目链接:点击查看 题目大意:给出一个2*n大小的矩阵,现在有m次操作,每次操作将某一个方格的状态置反,这里的每个方块都有两种状态,一种状态是可通行状态,另一种是不可通行状态,初始时所有方块都是可通行 ...

  3. Codeforce DIV2 614 SZU的cf集训round1 C ~ D

    C. NEKO's Maze Game 位运算+数据结构维护 题目大意:就是在一个2*n的迷宫里面,在任意时刻就会有一个位置从地面变成岩浆,或者从岩浆变成地面.问你在任意时刻你是否可以从(1,1)点跑 ...

  4. [A Dangerous Maze LightOJ - 1027 ][概率题]

    A Dangerous Maze LightOJ - 1027 题目大意:就是你有nnn个门每次你都会随机选一个门,这个门对应得数值如果是负的那么你将会在aia_iai​的时间后回到原来位置,如果是正 ...

  5. (POJ 3026) Borg Maze 最小生成树+bfs

    题目链接:http://poj.org/problem?id=3026. DescriptionThe Borg is an immensely powerful race of enhanced h ...

  6. [欧拉路]CF1152E Neko and Flashback

    1152E - Neko and Flashback 题意:对于长为n的序列c和长为n - 1的排列p,我们可以按照如下方法得到长为n - 1的序列a,b,a',b'. ai = min(ci, ci ...

  7. 【POJ 3026】Borg Maze

    [POJ 3026]Borg Maze 一个考察队搜索alien 这个考察队能够无限切割 问搜索到全部alien所须要的总步数 即求一个无向图 包括全部的点而且总权值最小(最小生成树 BFS+最小生成 ...

  8. Codeforces Round #554 (Div. 2) 1152A - Neko Finds Grapes

    学了这么久,来打一次CF看看自己学的怎么样吧 too young too simple 1152A - Neko Finds Grapes 题目链接:"https://codeforces. ...

  9. C++rat maze老鼠迷宫算法(附完整源码)

    rat maze老鼠迷宫的算法 rat maze老鼠迷宫的算法的完整源码(定义,实现,main函数测试) rat maze老鼠迷宫的算法的完整源码(定义,实现,main函数测试) #include & ...

最新文章

  1. pycharm设置环境变量和参数
  2. Block abstraction view(Create Reference)
  3. 应用中验证码的生成方法.
  4. SQL语法之基础查询(进阶1)and条件查询(进阶2)
  5. MyBatis 源码解读-配置解析过程
  6. Docker镜像由于代理问题导致不能下载的解决办法
  7. 使用mysqldump 导出sql数据
  8. [Linux][Ubuntu][14.04.3LTS]安装NVidia显卡驱动
  9. Cohen-SutherLand算法(编码算法)
  10. Oracle 根据业务创建新的用户
  11. Android 系统源码中添加 androidx 依赖
  12. Gradle下载及安装,配置IDEA
  13. 虽然没有见过凌晨四点的洛杉矶,但是我们见证了了凌晨灯火通明科技园:程序员的痛谁懂
  14. Matlab_R2016a 中文破解版 安装教程
  15. 电脑风扇转,屏幕、键盘和鼠标都不亮
  16. selenium切换窗口句柄
  17. element组件树形控件el-tree点击展开节点,节点重影
  18. 19年电赛经验总结-应该如何准备电赛
  19. 用户说明书,还是用户操作手册?
  20. Xcode写Python

热门文章

  1. h5微信页面在手机微信端和微信web开发者工具中都能正常显示,但是在pc端微信浏览器上打不开(显示空白)...
  2. shell 一些好玩的技巧.
  3. 【数据库开发】MySQL绿色版的下载和安装
  4. 调用android的拍照或本地相册选取再实现相片上传服务器,Android调用系统相机、本地相册上传图片(头像上传(裁剪)、多张图片上传)...
  5. my ReadBook_love
  6. 判断两个平面向量之间夹角是顺时针还是逆时针
  7. 详细介绍CoinList 2022 年夏季种子项目, web3概念最亮眼!
  8. 微信服务器保留几年记录_企业微信朋友圈管理的工具
  9. 杰理之脑连接样机蓝牙 , 开启音量同步 , 电脑无法大范围 量 调节音量【篇】
  10. 怎样查看电脑中的开机启动项?简单方法!如何禁止电脑开机启动的选项?