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 LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);//a为add
#endif
    int t;
    t=1;
    while(t--)solve();
    return 0;
}

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

质疑标普,理解标普,加入标普

上周我在文章里提到过&#xff0c;标普信息科技LOF(161128)出现套利机会。每天申购卖出&#xff0c;到现在一个账户56*6336润。 得益于美股七巨头轮流领涨&#xff0c;161128依旧坚挺&#xff0c;每天溢价都是10%&#xff0c;成交量1个多亿&#xff0c;场内新增份额才400万份&…

大模型生成的常见Top-k、Top-p、Temperature参数

参考&#xff1a; https://zhuanlan.zhihu.com/p/669661536 topK&#xff0c;topP https://www.douyin.com/video/7380126984573127945 主要是softmax产生的词表每个词的概率分布后&#xff0c; topK&#xff0c;比如K3&#xff0c;表示采样概率最大的前3个&#xff0c;其他全…

第一篇——怎样堵住我们人生错误的源头

目录 一、背景介绍二、思路&方案三、过程1.思维导图2.文章中经典的句子理解3.学习之后对于投资市场的理解4.通过这篇文章结合我知道的东西我能想到什么&#xff1f; 四、总结五、升华 一、背景介绍 再次开始了孙子兵法的学习&#xff0c;之前听完就让我醍醐灌顶&#xff0…

Python基础用法 之 变量

1.变量的定义 变量的作用&#xff1a;是⽤来保存数据的。定义的语法&#xff1a;变量名 数据值使用&#xff1a;直接使⽤变量名 即可使⽤变量中存储的数据。注意&#xff1a;变量必须先定义后使用。 (即 必须 先存⼊数据 才能 获取数据) 。 # 需求 1, 定义⼀个变量 保存你的名…

设计模式- 责任链模式Chain of Responsibility(行为型)

责任链模式(Chain of Responsibility) 责任链模式是一种行为模式&#xff0c;它为请求创建一个接收者对象的链&#xff0c;解耦了请求的发送者和接收者。责任链模式将多个处理器串联起来形成一条处理请求的链。 图解 角色 抽象处理者&#xff1a; 一个处理请求的接口&#xf…

TSP:人工原生动物优化器(APO)求解旅行商问题TSP(可以更改数据),MATLAB代码

一、旅行商问题介绍 二、人工原生动物优化算法求解TSP 2.1算法介绍 人工原生动物优化器&#xff08;Artificial Protozoa Optimizer &#xff0c;APO&#xff09;由Xiaopeng Wang等人于2024年提出&#xff0c;其灵感来自自然界中的原生动物。APO 模拟了原生动物的觅食、休眠和…

Spark-Shuffle阶段优化-Bypass机制详解

Spark概述 Spark-Shuffle阶段优化-Bypass机制详解 Spark的Bypass机制是一种特定情况下的优化策略&#xff0c;目的是减少Shuffle过程中不必要的排序开销&#xff0c;从而提升性能。当Shuffle分区数较少且数据量不大时&#xff0c;Bypass机制可以显著加快Shuffle速度。 1.什么…

统计套利—配对交易策略

配对交易是一种基于统计学的交易策略&#xff0c;通过两只股票的差价来获取收益&#xff0c;因而与很多策略不同&#xff0c;它是一种中性策略&#xff0c;理论上可以做到和大盘走势完全无关。 配对交易的基本原理是&#xff0c;两个相似公司的股票&#xff0c;其股价走势虽然在…

STM32CubeMX配置-外部中断配置

一、简介 MCU为STM32G070&#xff0c;配置为上升沿触发外部中断&#xff0c;在上升沿外部中断回调函数中进行相关操作。 二、外部中断配置 查看规格书中管教描述&#xff0c;找到I/O对应的外部中断线&#xff0c;然后进行如下上升沿触发外部中断配置。 三、生成代码 调用上升沿…

C语言:文件系统

一、目录和文件 在当前目录下使用touch 创建一个名为 -a的文件: touch -a ; // 错误&#xff0c; touch -- -a//正确 touch ./-a 正确 ls -n可以看到对象的用户id&#xff0c;可以在/etc/passwd中查看&#xff0c;/etc/group可以看到组号 获取文件属性 #include <sys/ty…

自动化测试xmind的常用技术

xmind思维导图的用法&#xff0c;我们在自动化测试中&#xff0c;写用例会用到思维导图工具xmind&#xff0c;下面总结xmind的一些常见用法。 在桌面上点击xmind图标&#xff0c;打开xmind 1、快捷按键 添加子主题:insert键 添加同级主题&#xff1a;回车键enter 删除&#…

爆火的治愈系插画工具又来了,额度居然有18w,根本花不完?

AI治愈插画又又又来了 今天给大家推荐一款完全免费的软件&#xff0c;用过的人都说好&#xff01; 先来看看我生成的图 制作过程非常简单&#xff0c;输入你想要生成的画面咒语。 工具地址&#xff1a;https://www.qiyuai.net/ 模型目前有两种 我上面的图就是用的第一种通用…

libharu维基页面

文章目录 安装Linux/UNIX:macOS:Windows (非 Cygwin/MSYS):使用 VCPKG 依赖管理器:注意&#xff1a; Cygwin/MSYS: 使用错误处理函数类型错误处理用户自定义错误处理函数使用用户自定义错误处理函数C语言中的错误处理C中的错误处理 其他编程语言错误代码列表总结 图像图形模式路…

【每天学会一个渗透测试工具】AWVS安装及使用指南

&#x1f31d;博客主页&#xff1a;泥菩萨 &#x1f496;专栏&#xff1a;Linux探索之旅 | 网络安全的神秘世界 | 专接本 | 每天学会一个渗透测试工具 ✨AWVS介绍 是应用漏洞扫描工具 &#x1f4a6;使用docker安装 docker pull dockermi3aka/awvs启动镜像 docker run -dit …

元数据、数据元、数据字典、数据模型及元模型的区别详解

在数据管理和分析领域&#xff0c;有许多相似的概念&#xff0c;如元数据、数据元、数据字典、数据模型和元模型。这些概念的定义和应用往往容易混淆。 数据元 数据元是通过一系列属性描述的数据单元&#xff0c;包括定义、标识、表示以及允许值等。这些属性帮助我们理解和使用…

SinNerf理解和效果

文章目录 SinNerf 解决的问题方法和结构自己训练的效果 SinNerf 解决的问题 该方法主要解决的问题是&#xff1a; 现有都使用多张照片来进行nerf 表示的学习&#xff0c;这篇文章的话&#xff0c;主要是想使用一张单视角的照片来Nerf表示的学习。通过从单张照片中得到的伪标签…

书生·浦语大模型实战营第二期作业六

1、安装环境&#xff1a; 2、安装legent和agentlego&#xff1a; 3、部署apiserver&#xff1a; 4、legent web demo&#xff1a; 5、没搜到&#xff0c;很尴尬&#xff1a; 6、自定义工具&#xff1a; 7、智能体“乐高”&#xff1a; 8、智能体工具&#xff0c;识别图片&#…

掌握高等数学、线性代数、概率论所需数学知识及标题建议

在数学的广袤领域中&#xff0c;高等数学、线性代数和概率论作为三大核心分支&#xff0c;不仅在理论研究中占据重要地位&#xff0c;更在实际应用中发挥着举足轻重的作用。为了深入理解和掌握这三门学科&#xff0c;我们需要掌握一系列扎实的数学知识。 高等数学所需数学知识 …

使用自定义注解进行权限校验

一&#xff0c;前言 对于一些重复性的操作我们可以用提取为util的方式进行处理&#xff0c;但也可以更简便一些&#xff0c;比如自定义个注解进行。选择看这篇文章的小伙伴想必都对注解不陌生&#xff0c;但是可能对它的工作原理不太清楚。这里我们用注解实现对接口的权限校验…

Centos7离线安装GCC,G++

系统&#xff1a;Centos7&#xff0c;Py版本&#xff1a;3.9.0 解压完python包后&#xff0c;执行./configure --prefix/usr/local/python39 --enable-shared编译时显示缺少相关编译器&#xff0c;即缺少gcc相关的C编译器&#xff0c;内容如下&#xff1a; 安装gcc所需要的依…