#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. LeetCode -- Linked List Circle ii

    Question: Given a linked list, return the node where the cycle begins. If there is no cycle, return  ...

  2. bzoj 4879 失控的数位板 4881 线段游戏 贪心,瞎搞

    [Lydsy1705月赛]失控的数位板 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 148  Solved: 33[Submit][Status][ ...

  3. ubuntu环境配置------增加右键菜单打开terminal

    直接安装一个软件包nautilus-open-terminal 终端输入:sudo apt-get install nautilus-open-terminal 重启系统!

  4. dbcp基本配置和重连配置

    转载自:http://agapple.iteye.com/blog/772507 最近在看一些dbcp的相关内容,顺便做一下记录,免得自己给忘记了. 1. 引入dbcp (选择1.4) Java代码  ...

  5. 通过设置nginx的client_max_body_size解决nginx+php上传大文件的问题

    通过设置nginx的client_max_body_size解决nginx+php上传大文件的问题:用nginx来做webserver的时,上传大文件时需要特别注意client_max_body_si ...

  6. Android百度地图的使用

    做关于位置或者定位的app的时候免不了使用地图功能,本人最近由于项目的需求需要使用百度地图的一些功能,所以这几天研究了一下,现写一下blog记录一下,欢迎大家评论指正! 一.申请AK(API Key) ...

  7. python每隔一段时间做一个事情

    #!/usr/bin/env python #coding:utf8 #Author:lsp #Date:下午2:17:54 #Version:0.1 #Function: 每隔一段时间做一个事情 f ...

  8. Linux 远程登录——(九)

    Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNormalTable ...

  9. HDU2389(二分图匹配Hopcroft-Carp算法)

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

  10. RabbitMQ消息队列(二): 工作队列

    1. 工作队列: 对于资源密集型任务,我们等待其处理完成在很多情况下是不现实的,比如无法在http的短暂请求窗口中处理大量耗时任务, 为了达到主线程无需等待,任务异步执行的要求,我们可以将任务加入任务 ...