Codeforces 869E The Untended Antiquity
题意:给定一个网格图,三种操作:1.在(r1,c1,r2,c2)处建围墙。2.删除(r1,c1,r2,c2)处的围墙。3.询问两点是否可达
思路比较巧妙,将围墙内的点赋加一个权值,询问的时候判断两个点的权是否相等即可。显然可以用二维树状数组实现。
#include<bits/stdc++.h>
using namespace std;
#define MAXN 2500+10
typedef long long LL;
const int seed=;
LL sum[MAXN][MAXN],n,m,q;
int lowbit(int x){return x&(-x);}
void add(int x,int y,LL val){
for(int i=x;i <= n;i+=lowbit(i))
for(int j=y;j <= m;j+=lowbit(j))
sum[i][j]+=val;
}
void update(int x1,int y1,int x2,int y2,LL val){
add(x1,y1,val);
add(x1,y2+,-val);
add(x2+,y1,-val);
add(x2+,y2+,val);
}
LL query(int x,int y){
LL tot=;
for(int i=x;i;i-=lowbit(i))
for(int j=y;j;j-=lowbit(j))
tot+=sum[i][j];
return tot;
}
int main(){
scanf("%d%d%d",&n,&m,&q);
while(q--){
int opt,x1,y1,x2,y2;
scanf("%d%d%d%d%d",&opt,&x1,&y1,&x2,&y2);
LL val=x1;
val=val*seed+y1;
val=val*seed+x2;
val=val*seed+y2;
if(opt==)update(x1,y1,x2,y2,val);
else if(opt==)update(x1,y1,x2,y2,-val);
else{
LL tmp1=query(x1,y1);
LL tmp2=query(x2,y2);
puts(tmp1==tmp2?"Yes":"No");
}
}
return ;
}
Codeforces 869E The Untended Antiquity的更多相关文章
- Codeforces 869E. The Untended Antiquity (二维Fenwick,Hash)
Codeforces 869E. The Untended Antiquity 题意: 在一张mxn的格子纸上,进行q次操作: 1,指定一个矩形将它用栅栏围起来. 2,撤掉一个已有的栅栏. 3,询问指 ...
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity
E. The Untended Antiquity 题目链接http://codeforces.com/contest/869/problem/E 解题心得: 1.1,x1,y1,x2,y2 以(x1 ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- CF869E The Untended Antiquity 解题报告
CF869E The Untended Antiquity 题目描述 \(\text{Adieu l'ami}\). Koyomi is helping Oshino, an acquaintance ...
- codeforces 869 E. The Untended Antiquity(树状数组)
题目链接:http://codeforces.com/contest/869/problem/E 题解:这题是挺好想到solution的但是不太好写,由于题目的特殊要求每个矩形不会重贴所以只要这两个点 ...
- 【CF Round 439 E. The Untended Antiquity】
time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standa ...
- CF439E:The Untended Antiquity - 哈希 + 二维树状数组
Magic Door 题目大意 有一个n*m的网格,支持三中操作: 1.在x1,y1,x2,y2为顶点的矩形周围围上栅栏 2.将x1,y1,x2,y2为顶点的矩形周围的栅栏拆掉 3.询问x1,y1,x ...
- Codeforces Round #439 (Div. 2)【A、B、C、E】
Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- HTML+CSS学习任务清单
HTML部分:掌握HTML的全部语法,他的主体结构,超连接及常用标记的使用 CSS部分:掌握CSS的三种选择器的使用,明白如何使用DIV+CSS进行网页布局,搞清楚浮动问题! 1,HTML的语法(包括 ...
- Linux学习(三)putty,xshell使用以及密匙登陆
一.认识xshell,putty 他们都是服务器登陆客户端.xshell用户体验更好一点.但这里都学一下. putty下载地址:https://www.chiark.greenend.org.uk/~ ...
- C++获取基类指针所指子类对象的类名
我们在程序中定义了一个基类,该基类有n个子类,为了方便,我们经常定义一个基类的指针数组,数组中的每一项指向都指向一个子类,那么在程序中我们如何判断这些基类指针是指向哪个子类呢? 关键字 typeid, ...
- Grunt打包seajs项目
在使用seajs时,常常将若干脚本分为多次require进来,这样开发中比较方便,但是,会增加http请求次数,在生产环境中需要进行打包合并.压缩等操作. 以Grunt构建工具为例,对一个seajs项 ...
- 可点击的icon按钮 无障碍 ARIA 可访问性
最简单: <input type="image" src="email.png" width="14" height="14 ...
- Apache降权和禁用PHP危险函数
测试环境: Windows Server 2003 + phpstudy 首先在win2003里运行phpstudy,这里注意需要选择应用系统服务模式,应用之后重启phpstudy. 打开系统服务(开 ...
- 为JS内置对象添加常用方法
1.字符串全部替换: String.prototype.replaceAll = function(s1,s2){ return this.replace(new RegExp(s1,"gm ...
- SQL命令语句进行大数据查询如何进行优化
SQL 大数据查询如何进行优化? 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索 2.应尽量避免在 where 子句中对字段进行 null 值 ...
- 多少牛逼的程序员毁在low逼的英文发音上(JAVA)
最最常用的关键词及音标 数据类型:boolean.byte.short.int.long.double.char.float.double. 包引入和包声明:import.package. 用于类和接 ...
- C语言系列之printf和%12d的用法(三)
看C语言程序的时候,往往会遇到printf函数输出,在此,我想总结一下printf的一般用法以及%12d是什么意思 printf函数的一般格式为 printf(格式控制,输出列表): 例如: prin ...