#439 Div2 E

题意

给出二维平面,有多个询问:

  1. 把某一区域围起来(围墙之间无交点)
  2. 移除某一区域的围墙(此时保证围墙一定存在)
  3. 选定两个位置问是否可以互相到达

分析

看起来很复杂,其实这道题限制颇多,实际并不用去寻找使得两个位置可以互相到达的路线,考虑二维树状数组维护某一点的状态,表示它被哪些矩形覆盖过,只要询问的两点被同样的矩形覆盖过,它们一定可以互相到达。对于覆盖的矩形,用一个随机数作为增加的值。

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的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  8. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  9. codeforces round367 div2.C (DP)

    题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...

随机推荐

  1. Win7命令mklink的使用

    C盘空间越来越小,在Win7里还标红了,心里看得不舒服,得想一些方法腾出一些空间.看了AppData,Chrome占了1G多的空间. 当时安装Chrome浏览器时因为不能指定安装目录,所以Chrome ...

  2. 第116讲 boost::algorithm::string之替换和删除

    http://www.360doc.com/content/16/0523/18/29304643_561672752.shtml

  3. HDU2389:Rain on your Parade(二分图最大匹配+HK算法)

    Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Ot ...

  4. bzoj 4624 农场种植 fft

    4624: 农场种植 Time Limit: 50 Sec  Memory Limit: 512 MBSubmit: 48  Solved: 31[Submit][Status][Discuss] D ...

  5. xcode 10 新特性

    这里主要介绍一下Xcode10 版本主要更新的内容.随着iOS12的发布,Xcode10已经可以从Mac App Store下载.Xcode10包含了iOS12.watchOS 5.macOS10.1 ...

  6. c# vs2008报表

    1. 做报表没做几次,第一次做的都忘记了,还好今天做一下就把报表弄成功了.报表中“参数字段”是可以变的,就是说需要自己赋值或者是要计算的.而在苏据库字段里面的是固定的值.不需要计算(注:有的字段查询出 ...

  7. 学习正则表达式及c#应用

    1.0正则表达式语法   正则表达式是一种文本模式,包括普通字符(例如,a 到 z 之间的字母)和特殊字符(称为“元字符”).模式描述在搜索文本时要匹配的一个或多个字符串. 正则表达式示例   表达式 ...

  8. HDFS 的Trash回收站

    1)在core-site.xml文件中添加这个配置 在每个节点(不仅仅是主节点)上添加配置 core-site.xml,增加如下内容 <property> <name>fs.t ...

  9. 【poj3294-不小于k个字符串中最长公共子串】后缀数组

    1.注意每两个串之间的连接符要不一样. 2.分组的时候要注意最后一组啊!又漏了! 3.开数组要考虑连接符的数量.100010是不够的至少要101000. #include<cstdio> ...

  10. 【洛谷 P1631】 序列合并 (堆)

    题目链接 直接暴力搞是\(n\)方的复杂度.\(n^2\)个数选\(n\)个最小的,容易想到堆. 我们堆里记录两个信息:到\(A\)数组哪个位置了,到\(B\)数组哪个位置了, 我直接把这两个信息存在 ...