#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. [NOI.AC省选模拟赛3.30] Mas的童年 [二进制乱搞]

    题面 传送门 思路 这题其实蛮好想的......就是我考试的时候zz了,一直没有想到标记过的可以不再标记,总复杂度是$O(n)$ 首先我们求个前缀和,那么$ans_i=max(pre[j]+pre[i ...

  2. BZOJ3242 [Noi2013]快餐店 【环套树 + 单调队列dp】

    题目链接 BZOJ3242 题解 题意很清楚,找一点使得最远点最近 如果是一棵树,就是直径中点 现在套上了一个环,我们把环单独拿出来 先求出环上每个点外向树直径更新答案,并同时求出环上每个点外向的最远 ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. CVPR2014 Objectness 源码转换(完整版) VS2012 X64 –>win32

    一.版本转换  1.将源码中vs2012 X64版本转换为vs2012 win32版本. 2.源码下载及其相关资料下载http://mmcheng.net/zh/bing/ 3.需要下载源码(Pape ...

  5. API网关Kong部署和使用文档

    KONG安装使用说明 系统版本:ubuntu14 1.下载安装包 $ wget https://github.com/Mashape/kong/releases/download/0.8.3/kong ...

  6. JS alert()、confirm()、prompt()的区别

    这三个都是属于弹框类型的 使用警告.提示和确认消息框来获得用户的输入.这些消息框是 window 对象的接口方法.由于 window 对象位于对象层次的顶层,因此实际应用中不必使用这些消息框的全名(例 ...

  7. maven工程开启jetty调试

    转摘自:http://czj4451.iteye.com/blog/1942437 准备工作: a. 在pom.xml中配置jetty插件: <plugins> <plugin> ...

  8. VC遍历窗体控件的实现

    最近在写控制台,在设计界面按钮风格时不想通过每个按钮的ID来获取其句柄,而是通过遍历窗体所有控件,然后判断其控件类型进而来实现. 代码如下: // 遍历得到页面中的所有Button控件,依次设定其样式 ...

  9. HDU1267 下沙的沙子有几粒? 基础DP

    题目链接 题意:给定m个H和n个D(1<=n,m<=20),问这些字母构成的序列中,对于任意位置,从左开始数H的累积个数总是不比D的累计数少的排列有多少种. 题解:二维DP,画一个正方形, ...

  10. [Leetcode Week1]Longest Substring Without Repeating Characters

    Longest Substring Without Repeating Characters题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/longes ...