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.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- git常用命令集合
git命令 git init:创建一个仓库并在目录下新建一个.git的文件(初始化一个git仓库) 注:.git文件在工作区,是一个隐藏文件(用ls -ah命令查看),但是它不算工作区,而是git 的 ...
- 套接字(linux相关)
前言:略 一.前因 一切从tcp.udp开始. 众所周知,网络模型一般有两种模型,一种为OSI概念模型(七层),另一种为tcp/ip网络模型(四层). tcp/ip应用层对应OSI的应用层.显示层.会 ...
- A strange lift
Problem Description There is a strange lift.The lift can stop can at every floor as you want, and th ...
- #define is unsafe
#define is unsafe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- git使用教程之git基础
1 获取Git仓库 在现有目录中初始化仓库 git init 克隆现有的仓库 git clone https://github.com/yangwang12345/node_test.git Git ...
- 腾讯Java程序员第二轮面试11个问题,你会几个?
此前,分享了阿里巴巴.网易.百度等多家名企的JAVA面试题. 这也引来了不少程序员网友们的围观. 其中,也有相当一部分网友是已经从事Java开发好多年的程序员,当他们阅读完JAVA面试题的反应是:一个 ...
- selenium+testN自动化测试框架搭建
自动化测试框架搭建 1 Java环境的搭建 1.1访问oracle的官网下载最新版本的jdk http://www.oracle.com/technetwork/java/javase/downloa ...
- [java语言]——InetAddress类的getByName()方法
InetAddress---表示互联网协议(IP)地址 ---InetAddress.getByName("www.163.com")----在给定主机名的情况下确定主机的IP地址 ...
- 64位win7下安装Boost 1.59.0 + boost.python 1.59.0 + gccxml + pygccxml + pyplusplus(py++)
由于安装过程中实在是出现了N多问题,所以不得不专门写个帖子来记录一下这破东西在Win7下的安装过程,避免以后还要再用的时候踩坑. 1.Boost简介 Boost库是一个可移植.提供源代码的C++库,作 ...
- 微信分享 JSSDK的使用
我现在做过的在微信中运行的项目,基本上都有微信分享功能,所以,会使用JSSDK分享页面是非常重要的.分享功能的代码一般会放在beforeCreate或mounted钩子中,代码如下: this.$ht ...