Codeforces #439 Div2 E
#439 Div2 E
题意
给出二维平面,有多个询问:
- 把某一区域围起来(围墙之间无交点)
- 移除某一区域的围墙(此时保证围墙一定存在)
- 选定两个位置问是否可以互相到达
分析
看起来很复杂,其实这道题限制颇多,实际并不用去寻找使得两个位置可以互相到达的路线,考虑二维树状数组维护某一点的状态,表示它被哪些矩形覆盖过,只要询问的两点被同样的矩形覆盖过,它们一定可以互相到达。对于覆盖的矩形,用一个随机数作为增加的值。
code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2515;
ll f[MAXN][MAXN];
void update(int x, int y, ll z) {
while(x < MAXN) {
int j = y;
while(j < MAXN) {
f[x][j] += z;
j += j & -j;
}
x += x & -x;
}
}
ll query(int x, int y) {
ll sum = 0;
while(x) {
int j = y;
while(j) {
sum += f[x][j];
j -= j & -j;
}
x -= x & -x;
}
return sum;
}
map<array<int, 4>, ll> mp;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
while(q--) {
int t, a, b, c, d;
cin >> t >> a >> b >> c >> d;
if(t == 1) {
ll tmp = 1LL * rand() * rand();
mp[{a, b, c, d}] = tmp;
update(a, b, tmp);
update(c + 1, d + 1, tmp);
update(c + 1, b, -tmp);
update(a, d + 1, -tmp);
} else if(t == 2) {
ll tmp = mp[{a, b, c, d}];
mp[{a, b, c, d}] = 0;
update(a, b, -tmp);
update(c + 1, d + 1, -tmp);
update(c + 1, b, tmp);
update(a, d + 1, tmp);
} else {
ll t1 = query(a, b);
ll t2 = query(c, d);
if(t1 != t2) cout << "No\n";
else cout << "Yes\n";
}
}
return 0;
}
Codeforces #439 Div2 E的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
随机推荐
- Spring AOP前置通知实例讲解与AOP详细解析
一.引出问题 有个接口TestServiceInter,有两个实现方法TestService和Test2Service.他们都有sayHello():我们的需求是在调用这两个方法之前,要先完成写日志的 ...
- 工具——SVN常用命令
SVN一般都是团队合作做一个项目所需用到的,为了是版本的统一 ;1. Check out——从服务器端取得代码 把服务器资料库里存放的某个项目代码取出来,放到本地主机中,这个动作叫做“check ...
- 阿里巴巴前端面试parseInt()函数的面试题
JavaScript 是弱类型语言,为了保证数值的有效性,在处理数值的时候,我们可以对数值字符串进行强行转换.如 parseInt 取整和 parseFloat 取浮点数.Java 也有 Intege ...
- HDU 5655 四边形判断
CA Loves Stick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- CentOS 安装 debuginfo-install
安装debuginfo相关的包步骤如下: 1. 修改文件/etc/yum.repos.d/CentOS-Debuginfo.repo中的enabled参数,将其值修改为1 2. 使用命令: yum i ...
- 自定义orderBy字母函数
orderedUsers: function () { var arr = this.users; for (var i = 0; i < arr.length - 1; i++) { for ...
- iconfont字体图标
1.1.进入阿里图标网站 http://www.iconfont.cn/ 1.2.在购物车里添加自己需要的字体图标 1.3.下载代码 1.4.解压过后,找到iconfont.css,放在你的项目里,需 ...
- python每隔一段时间做一个事情
#!/usr/bin/env python #coding:utf8 #Author:lsp #Date:下午2:17:54 #Version:0.1 #Function: 每隔一段时间做一个事情 f ...
- Python基础(5)_文件操作
一.文件处理流程 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 二.文件打开模式 打开文件时,需要指定文件路径和以何等方式打开文件,打开后,即可获取该文件句柄,日后通过此文 ...
- RPC-Thrift(二)
TTransport TTransport负责数据的传输,先看类结构图. 阻塞Server使用TServerSocket,它封装了ServerSocket实例,ServerSocket实例监听到客户端 ...