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.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- 前后端分离跨服务器文件上传-Java SpringMVC版
近来工作上不上特别忙,加上对后台java了解一点,所以就抽时间,写了一个java版本的前后端分离的跨服务器文件上传功能,包括前后端代码. 一.Tomcat服务器部分 1.Tomcat服务器 单独复制一 ...
- ubuntu-17.10 安装 FANN
因为想用C语言写神经网络,不用已有的库的话,又太难了,所以准备安装一个夸平台的FANN库, 源文件下载地址http://leenissen.dk/fann/wp/download/,我下载的是最新 ...
- 1016: [JSOI2008]最小生成树计数
1016: [JSOI2008]最小生成树计数 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 6200 Solved: 2518[Submit][St ...
- poj 2566 Bound Found
Bound Found Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4384 Accepted: 1377 Spe ...
- jumpserver安装详解
环境说明 主机为最小 安装的centos6.9 x86_64. [root@m01 ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [ro ...
- Android 开发笔记___图像视图__简单截屏
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- 用笔记本写C程序
首先在Visual Studio Tools 文件中打开 Visual Studio 命令提示(2010),输入命令 notepad 打开记事本,写好程序保存,保存类型:所有文档 文件名:1.c . ...
- JavaScript系列-----Object之toString()和valueOf()方法 (2)
深入理解toString()和valueOf()函数 1.我们为什么要了解这两种方法 众所周知,toString()函数和valueOf函数,这两个函数是Object类的对象生来就拥有的,而且他们还可 ...
- DbContext 和ObjectContext
近日学习新知识,用到CallContext数据槽,一直使用ObjectContext 但同时又在学习EF CodeFirst,上下文定义使用的 DbContext 这时问题来了,如何把DbContex ...
- bzoj1003
考虑dp[i]表示前i天的最小总成本. 枚举上一次在第j天之后对路线进行了修改,那么就由dp[j]转移至dp[i],转移的代价是把第[j+1,i]天所有被占用的点全删掉后的最短路(不连通当然就是INF ...