E. The Untended Antiquity

Problem Statement

Adieu l’ami.
    Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around the abandoned Eikou Cram School building, Oshino’s makeshift residence.
    The space is represented by a rectangular grid of n × m cells, arranged into n rows and m columns. The c-th cell in the r-th row is denoted by (r, c).
    Oshino places and removes barriers around rectangular areas of cells. Specifically, an action denoted by “1 r1 c1 r2 c2” means Oshino’s placing barriers around a rectangle with two corners being (r1, c1) and (r2, c2) and sides parallel to squares sides. Similarly, “2 r1 c1 r2 c2” means Oshino’s removing barriers around the rectangle. Oshino ensures that no barriers staying on the ground share any common points, nor do they intersect with boundaries of the n × m area.
    Sometimes Koyomi tries to walk from one cell to another carefully without striding over barriers, in order to avoid damaging various items on the ground. “3 r1 c1 r2 c2” means that Koyomi tries to walk from (r1, c1) to (r2, c2) without crossing barriers.
    And you’re here to tell Koyomi the feasibility of each of his attempts.

Input

The first line of input contains three space-separated integers n, m and q (1 ≤ n, m ≤ 2 500, 1 ≤ q ≤ 100 000) — the number of rows and columns in the grid, and the total number of Oshino and Koyomi’s actions, respectively.
    The following q lines each describes an action, containing five space-separated integers t, r1, c1, r2, c2 (1 ≤ t ≤ 3, 1 ≤ r1, r2 ≤ n, 1 ≤ c1, c2 ≤ m) — the type and two coordinates of an action. Additionally, the following holds depending on the value of t:
     · If t = 1: 2 ≤ r1 ≤ r2 ≤ n - 1, 2 ≤ c1 ≤ c2 ≤ m - 1;
     · If t = 2: 2 ≤ r1 ≤ r2 ≤ n - 1, 2 ≤ c1 ≤ c2 ≤ m - 1, the specified group of barriers exist on the ground before the removal.
     · If t = 3: no extra restrictions.

Output

For each of Koyomi’s attempts (actions with t = 3), output one line — containing “Yes” (without quotes) if it’s feasible, and “No” (without quotes) otherwise.

Examples

Example 1
    Input
        5 6 5
        1 2 2 4 5
        1 3 3 3 3
        3 4 4 1 1
        2 2 2 4 5
        3 1 1 4 4
    Output
        No
        Yes
Example 2
    Input
        2500 2500 8
        1 549 1279 1263 2189
        1 303 795 1888 2432
        1 2227 622 2418 1161
        3 771 2492 1335 1433
        1 2017 2100 2408 2160
        3 48 60 798 729
        1 347 708 1868 792
        1940 2080 377 1546
    Output
        No
        Yes
        No

Note

For the first example, the situations of Koyomi’s actions are illustrated below.

题意

给你一个n*m大小的平面直角坐标系,再给你q个操作,每个操作有五个参数t,x,y,xx,yy,其中t是操作类型,t=1表示在平面直角坐标系上添加了一个左上角为(x,y),右下角为(xx,yy)的矩形,t=2则表示删除(保证在删除前已经添加了);而t=3则是询问,一个人从起点(x,y)走到终点(xx,yy)能否走到,走的时候不能穿过任何一个矩形。

思路

这题……有人用O(q^2)水过去了233..我的做法是随机+二维树状数组。对于每一个添加的矩形,我们给他随机rand一个值,并在二维树状数组里加上这个值,用一个map

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void readInt(int &x) {x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;
}
inline void readLong(ll &x) {x=0;ll f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;
}
/*================Header Template==============*/
#define lb(x) x&(-x)
#define mk make_pair
typedef pair<int,int> pii;
ll n,m,q,tree[3010][3010],type,x,y,xx,yy;
map<pii,ll> mp;
inline void add(ll x,ll y,ll Add) {for(ll i=x;i<=n;i+=lb(i))for(ll j=y;j<=m;j+=lb(j))tree[i][j]+=Add;
}
inline ll ssum(ll x,ll y) {ll ans=0;for(ll i=x;i>0;i-=lb(i))  for(ll j=y;j>0;j-=lb(j))  ans+=tree[i][j];return ans;
}
inline ll randll() {ll x=rand();x=(x<<12)|rand();x=(x<<12)|rand();x=(x<<12)|rand();return x;
}
int main() {srand(time(0));readLong(n);readLong(m);readLong(q);for(ll i=1;i<=q;i++){readLong(type);readLong(x);readLong(y);readLong(xx);readLong(yy);if(type==1) {xx++;yy++;ll tmp=randll();pii now=mk(x*n+y,xx*n+yy);mp[now]=tmp;add(x,y,tmp);add(x,yy,-tmp);add(xx,y,-tmp);add(xx,yy,tmp);}else if(type==2) {xx++;yy++;pii now=mk(x*n+y,xx*n+yy);ll k=mp[now];add(x,y,-k);add(x,yy,k);add(xx,y,k);add(xx,yy,-k);          }else if(type==3) {ll tmpx=ssum(x,y),tmpy=ssum(xx,yy);if(tmpx==tmpy)puts("Yes");elseputs("No");}}return 0;
}

Codeforces Round #439 (Div. 2) E. The Untended Antiquity相关推荐

  1. Codeforces Round #439 (Div. 2) E. The Untended Antiquity 二维线段树||二维树状数组

    http://codeforces.com/contest/869/problem/E 题意:n*m的矩阵,q次操作,三种类型 类型1:给指定矩阵加上围栏 类型2:给指定矩阵去掉围栏 类型3:查询两点 ...

  2. Codeforces Round #439 (Div. 2) E. The Untended Antiquity (hash+数状数组)

    这个题,做出来的人很多,我感觉是数据不够强,我看了很多人的代码直接暴力也能过了,直接暴力如果数据够强的话肯定是时间超限,边缘数据不够强.如果和上次一样估计很多人的E会GG.我看到一位OIdalao的代 ...

  3. Codeforces Round #439 (Div. 2) E. The Untended Antiquity(二维BIT)

    题意:在 n×m 的二维图上,有三种操作: 1 r1 c1 r2 c2 表示沿着 (r1, c1, r2, c2) 所表示的矩形的外边框建围墙.(其中 (r1, c1) 为矩形左上角,(r2, c2) ...

  4. Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学

    - This is not playing but duty as allies of justice, Nii-chan! - Not allies but justice itself, Onii ...

  5. Codeforces Round #439 (Div. 2)

    一句话题意: A:传送门 题意:给定两个长为\(n\)的数组\(a\),\(b\),令\(ans=\)有序对\((i,j)\)的个数使得\(a_i\ xor\ b_j\)在这\(2n\)个数中出现过, ...

  6. Codeforces Round #439 (Div. 2)C - The Intriguing Obsession(简单dp)

    传送门 题意 给出三个集合,每个集合的元素数量为a,b,c,现在需要连边,满足集合内元素不可达或最短路为3,求可行方案数 分析 设dp[i][j]为a集合元素为i个,b集合元素为j个的可行方案,易知( ...

  7. Codeforces Round #439 (Div. 2) A. The Artful Expedient

    A. The Artful Expedient Problem Statement Rock- Paper!     After Karen have found the deterministic ...

  8. 【Codeforces Round #439 (Div. 2) A】The Artful Expedient

    [链接] 链接 [题意] [题解] 暴力 [错的次数] 在这里输入错的次数 [反思] 在这里输入反思 [代码] #include <bits/stdc++.h> using namespa ...

  9. Codeforces Round #439 (Div. 2) C.The Intriguing Obsession(组合数、记忆化搜索)

    题意: 给出a个红色点,b个蓝色点,c个紫色点,我们可以在这些点之间连任意数量长度为1的边,但是限制同颜色的点之间不能连边且同颜色的点之间的最短路径至少为3,求方案数% 998244353, a,b, ...

最新文章

  1. Python中if语句练习题
  2. MyEclipse10整合Axis2插件
  3. android从放弃到精通 第七天 tomorrow
  4. CentOS iso镜像文件做本地源
  5. 我们工作到底为了什么?
  6. 《JAVA与模式》之建造模式
  7. junit mockito_从工作中清除代码–使用JUnit 5,Mockito和AssertJ编写可执行规范
  8. 模拟电路概念知识体系梳理(基础部分)
  9. Hibernate第十一篇【配置C3P0数据库连接池、线程Session】
  10. java web 润乾报表教程_润乾报表开发 基础教程.ppt
  11. 【数据结构与算法】浅析堆栈以及数据结构的堆和栈
  12. Java : java基础(1)
  13. CHM文件打开显示乱码的解决方法
  14. CentOS7中的firewall 和 iptables
  15. U盘加密软件测试简历,U盘加密软件哪个好用?2020U盘加密软件推荐
  16. Spark、Hadoop大数据平台搭建
  17. opencv学习日记
  18. 天地三才阵——【Java三大特征】
  19. 完美C Perfect C 丰胸胶囊
  20. 破解一个已经连接好的数据库密码

热门文章

  1. 百家号同步公众号的自媒体工具有吗?
  2. java实现汉诺塔游戏(递归)(附超详细易懂注释)
  3. python按照号段生成手机号接收验证码_django 发送手机验证码的示例代码
  4. JavaScript之排他思想详述
  5. python是什么意思中文、好学吗-零基础学python难吗?好学吗?
  6. 杀不死的人狼——我读《人月神话》(一)
  7. 案例十三、模仿微信打飞机游戏
  8. ENVI中的3种图像分类方法
  9. Unicode双向算法详解(bidi算法)(二)
  10. DZZOffice(大桌子)企业文档协同平台教程系列(三)——ONLYOFFICE社区版部署、配置