C. Rooks Defenders(树状数组)

You have a square chessboard of size n×nn×n. Rows are numbered from top to bottom with numbers from 11 to nn, and columns — from left to right with numbers from 11 to nn. So, each cell is denoted with pair of integers (x,y)(x,y) (1≤x,y≤n1≤x,y≤n), where xx is a row number and yy is a column number.

You have to perform qq queries of three types:

  • Put a new rook in cell (x,y)(x,y).
  • Remove a rook from cell (x,y)(x,y). It's guaranteed that the rook was put in this cell before.
  • Check if each cell of subrectangle (x1,y1)−(x2,y2)(x1,y1)−(x2,y2) of the board is attacked by at least one rook.

Subrectangle is a set of cells (x,y)(x,y) such that for each cell two conditions are satisfied: x1≤x≤x2x1≤x≤x2 and y1≤y≤y2y1≤y≤y2.

Recall that cell (a,b)(a,b) is attacked by a rook placed in cell (c,d)(c,d) if either a=ca=c or b=db=d. In particular, the cell containing a rook is attacked by this rook.

Input

The first line contains two integers nn and qq (1≤n≤1051≤n≤105, 1≤q≤2⋅1051≤q≤2⋅105) — the size of the chessboard and the number of queries, respectively.

Each of the following qq lines contains description of a query. Description begins with integer tt (t∈{1,2,3}t∈{1,2,3}) which denotes type of a query:

  • If t=1t=1, two integers xx and yy follows (1≤x,y≤n1≤x,y≤n) — coordinated of the cell where the new rook should be put in. It's guaranteed that there is no rook in the cell (x,y)(x,y) at the moment of the given query.
  • If t=2t=2, two integers xx and yy follows (1≤x,y≤n1≤x,y≤n) — coordinates of the cell to remove a rook from. It's guaranteed that there is a rook in the cell (x,y)(x,y) at the moment of the given query.
  • If t=3t=3, four integers x1,y1,x2x1,y1,x2 and y2y2 follows (1≤x1≤x2≤n1≤x1≤x2≤n, 1≤y1≤y2≤n1≤y1≤y2≤n) — subrectangle to check if each cell of it is attacked by at least one rook.

It's guaranteed that among qq queries there is at least one query of the third type.

Output

Print the answer for each query of the third type in a separate line. Print "Yes" (without quotes) if each cell of the subrectangle is attacked by at least one rook.

Otherwise print "No" (without quotes).

Example

input

Copy

8 10
1 2 4
3 6 2 7 2
1 3 2
3 6 2 7 2
1 4 3
3 2 6 4 8
2 4 3
3 2 6 4 8
1 4 8
3 2 6 4 8

output

Copy

No
Yes
Yes
No
Yes

Note

Consider example. After the first two queries the board will look like the following picture (the letter RR denotes cells in which rooks are located, the subrectangle of the query of the third type is highlighted in green):

Chessboard after performing the third and the fourth queries:

uploading.4e448015.gif

正在上传…重新上传取消正在上传…重新上传取消

Chessboard after performing the fifth and the sixth queries:

uploading.4e448015.gif

正在上传…重新上传取消正在上传…重新上传取消

Chessboard after performing the seventh and the eighth queries:

Chessboard after performing the last two queries:

uploading.4e448015.gif

正在上传…重新上传取消正在上传…重新上传取消

思路:

1,能不能撞击的关键在于行列是否出现过

2,用前缀和和差分来实现

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
const int maxj=2e5+100,mod=1e9+7,inf=0x7f7f7f7f7f7f7f7f;
template<class t> void read(t &res){char c;t flag=1;while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';while((c=getchar())>='0'&&c<='9')res+=c-'0';res*=flag;
}
int n,q;
int sum1[maxj],sum2[maxj];
struct bit{int lowbit(int x){return x&-x;}void add(int x,int c,int sum[]){while(x <= n)sum[x]+=c,x+=lowbit(x);}int getsum(int x,int sum[]){int res=0;while(x)res+=sum[x],x-=lowbit(x);return res;}
}t;
int x[maxj],y[maxj];
void solve(){  //对行列做标记cin>>n>>q;while(q--){int v;cin>>v;if(v==1){int l,r;cin>>l>>r;x[l]++;y[r]++;if(x[l]==1)t.add(l,1,sum1);//可多次放,多次拿if(y[r]==1)t.add(r,1,sum2);}else if(v==2){int l,r;cin>>l>>r;x[l]--;y[r]--;if(x[l]==0)t.add(l,-1,sum1);if(y[r]==0)t.add(r,-1,sum2);}else{int l,r,ll,rr;cin>>l>>r>>ll>>rr;if(t.getsum(ll,sum1)-t.getsum(l-1,sum1)==ll-l+1||t.getsum(rr,sum2)-t.getsum(r-1,sum2)==rr-r+1)cout<<"Yes"<<'\n';else cout<<"No"<<'\n';}}
}
int32_t main(){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCALfreopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);//a为add
#endifint t;t=1;while(t--)solve();return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/1452371.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

省去烦恼!轻松实现一台电脑登录多个微信号的秘诀揭秘!

你知道如何在同一台电脑上登录多个微信号&#xff0c;并实现聚合聊天吗&#xff1f; 今天&#xff0c;我将分享一个多微管理神器——个微管理系统&#xff0c;帮助你解决这一问题&#xff01; 1、多号同时登录&#xff0c;聚合聊天 无论你有多少个微信号&#xff0c;都可以一…

Sobel边缘检测

声明&#xff1a;学习过程中的知识总结&#xff0c;欢迎批评指正。 基本原理 灰度处理&#xff1a;边缘检测是基于图像亮度变化实现的&#xff0c;而图像的亮度信息通过灰度图像体现&#xff0c;因此需要把彩色图像转换成灰度图像。平滑处理&#xff1a;可以使用高斯滤波等滤…

Vscode flake8插件 python代码语法格式检测/代码过长等误报设置

在vscode中python格式检测使用flake8插件很方便&#xff0c;但是经常会报出一些不必要错误&#xff0c;影响开发效率&#xff0c;忽略这些错误可以帮助减少对于特定项目可能不太关键的PEP 8警告或代码风格问题的干扰&#xff0c;特别是在项目有自己的格式化和编码标准时。使用f…

Golang——gRPC gateway网关

前言 etcd3 API全面升级为gRPC后&#xff0c;同时要提供REST API服务&#xff0c;维护两个版本的服务显然不大合理&#xff0c;所以gRPC-gateway诞生了。通过protobuf的自定义option实现了一个网关。服务端同时开启gRPC和HTTP服务&#xff0c;HTTP服务接收客户端请求后转换为gr…

(微服务项目实战)预付卡系统券模块系统设计

1 技术架构 框架描述版本JDKJava运行环境17SpringBoot基于SpringBoot完成后端代码开发3.2.6DubboApache Dubbo 是一款易用、高性能的 WEB 和 RPC 框架&#xff0c;同时为构建企业级微服务提供服务发现、流量治理、可观测、认证鉴权等能力、工具与最佳实践3.xSpringCloud微服务…

WINUI——Trigger(触发器)使用小结

背景 WINUI不提供原生的Trigger支持&#xff0c;推荐使用VisualStateManager进行操作&#xff1b;然对于从WPF转WINUI的开发人员而言&#xff0c;经常会想用Trigger解决问题&#xff0c;鉴于此社区推出了CommunityToolkit.WinUI.Triggers以支持Trigger的使用。 使用方法 1.项…

Sky Master ULTIMATE Volumetric Skies Clouds Weather

该系统包含行业级优化的体积云、海洋系统、GI 代理,以及用于全局光照的优化 SEGI 和基于物理的天空渲染系统,且带有大气散射。 Sky Manager 可提供自动或按需的日/夜循环以及平滑的天气过渡。 Skybox 模式提供了与 Unity 及其功能(IBLGI、GI、Skybox)的完整集成。 先进的粒…

【YashanDB知识库】PHP使用ODBC驱动无法获取长度为256char以上的数据

【问题分类】驱动使用 【关键字】ODBC、驱动使用、PHP、 【问题描述】PHP使用PDO_ODBC连接yashan数据库&#xff0c;获取数据类型大于或等于varchar(256 char)的数据时出现异常&#xff0c;数据无法正常获取&#xff0c;BLOB等字段也无法正常获取&#xff0c;并且该问题会导致…

【C语言】解决C语言报错:Undefined Reference

文章目录 简介什么是Undefined ReferenceUndefined Reference的常见原因如何检测和调试Undefined Reference解决Undefined Reference的最佳实践详细实例解析示例1&#xff1a;缺少函数定义示例2&#xff1a;函数声明和定义不匹配示例3&#xff1a;未链接必要的库示例4&#xff…

useEffect的概念以及使用(对接口)

// useEffect的概念以及使用 import {useEffect, useState} from reactconst Url"http://geek.itheima.net/v1_0/channels"function App() {// 创建状态变量const [lustGet,setLustGet]useState([]);// 渲染完了之后执行这个useEffect(() > {// 额外的操作&#x…

【C++】stack、queue和deque的使用

&#x1f497;个人主页&#x1f497; ⭐个人专栏——C学习⭐ &#x1f4ab;点击关注&#x1f929;一起学习C语言&#x1f4af;&#x1f4ab; 目录 导读 一、stack 1. stack介绍 2. stack使用 二、queue 1. queue介绍 2. queue使用 三、deque 1. deque介绍 2. deque的…

大数据实训项目(小麦种子)-04、大数据实训项目JavaWeb环境搭建

文章目录 前言运行前准备工作1、安装Hadoop3.1.0配置winutils原因描述配置方式注意点&#xff08;hadoop.dll拷贝System32目录下&#xff09; 2、hive运行报错&#xff08;The dir: /tmp/hive on HDFS should be writable. &#xff09; 项目环境搭建参考资料 前言 博主介绍&a…

Python设计模式 - 简单工厂模式

定义 简单工厂模式是一种创建型设计模式&#xff0c;它通过一个工厂类来创建对象&#xff0c;而不是通过客户端直接实例化对象。 结构 工厂类&#xff08;Factory&#xff09;&#xff1a;负责创建对象的实例。工厂类通常包含一个方法&#xff0c;根据输入参数的不同创建并返…

357. 统计各位数字都不同的数字个数

. - 力扣&#xff08;LeetCode&#xff09; class Solution { public:int countNumbersWithUniqueDigits(int n) {vector<int> f(n1);if(n0)return 1;if(n1)return 10;f[0]1;f[1]10;for(int i2;i<n;i)f[i] f[i-1] (f[i-1]-f[i-2])*(10-(i-1));return f[n];} };

电子行业实施MES管理系统的时机是什么

随着信息技术的飞速发展&#xff0c;MES生产管理系统逐渐成为电子企业实现自动化生产和信息化管理的必备工具。那么&#xff0c;何时是电子企业实施MES管理系统的最佳时机呢&#xff1f; 1.生产过程中出现了问题&#xff0c;需要优化和改进。 2.企业需要提高产品交付和响应速…

港理工最新综述:基于LLM的text-to-SQL调查(方法实验数据全面梳理)1

【摘要】文本到SQL旨在将自然语言问题转换为可执行的SQL语句,这对用户提问理解、数据库模式理解和SQL生成都是一个长期存在的挑战。传统的文本到SQL系统包括人工工程和深度神经网络。随后,预训练语言模型(PLMs)被开发并用于文本到SQL任务,取得了可喜的成绩。随着现代数据库变得…

【AIGC】MetaGPT原理以及应用

目录 MetaGPT原理 MetaGPT应用 MetaGPT和传统编程语言相比有什么优势和劣势 视频中的PPT 参考资料 MetaGPT原理 MetaGPT是一种多智能体框架&#xff0c;它结合了元编程技术&#xff0c;通过标准化操作程序&#xff08;SOPs&#xff09;来协调基于大语言模型的多智能体系统…

Python学习打卡:day06

day6 笔记来源于&#xff1a;黑马程序员python教程&#xff0c;8天python从入门到精通&#xff0c;学python看这套就够了 目录 day648、函数综合案例49、数据容器入门50、列表的定义语法51、列表的下标索引1、列表的下标&#xff08;索引&#xff09;2、列表的下标&#xff08…

数据防泄漏的六个步骤|数据防泄漏软件有哪些

在当前复杂多变的网络安全环境下&#xff0c;数据防泄漏软件成为了企业信息安全架构中不可或缺的一环。下面以安企神软件为例&#xff0c;告诉你怎么防止数据泄露&#xff0c;以及好用的防泄露软件。 1. 安企神软件 安企神软件是当前市场上备受推崇的企业级数据防泄漏解决方案…

等待 chrome.storage.local.get() 完成

chrome.storage.local.get() 获取存储处理并计数&#xff0c;内部计数正常&#xff0c;外部使用始终为0&#xff0c;百思不得其解。 如何在继续执行之前等待异步chrome.storage.local.get()完成-腾讯云开发者社区-腾讯云 (tencent.com) 原来我忽略了异步问题&#xff0c;最简…