您的位置:首页 > 产品设计 > UI/UE

E. The Untended Antiquity[二维BIT更新区间] 好题!

2018-03-18 10:58 399 查看
E. The Untended Antiquity

time limit per test
2 seconds

memory limit per test
512 megabytes

input
standard input

output
standard output

Adieu l'ami.

Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around the abandoned Eikou Cram School building, Oshino's makeshift residence.

The space is represented by a rectangular grid of n × m cells, arranged into n rows
and m columns. The c-th
cell in the r-th row is denoted by (r, c).

Oshino places and removes barriers around rectangular areas of cells. Specifically, an action denoted by "1 r1 c1 r2 c2"
means Oshino's placing barriers around a rectangle with two corners being (r1, c1) and (r2, c2) and
sides parallel to squares sides. Similarly, "2 r1 c1 r2 c2"
means Oshino's removing barriers around the rectangle. Oshino ensures that no barriers staying on the ground share any common points, nor do they intersect with boundaries of the n × m area.

Sometimes Koyomi tries to walk from one cell to another carefully without striding over barriers, in order to avoid damaging various items on the ground. "3 r1 c1 r2 c2"
means that Koyomi tries to walk from (r1, c1) to (r2, c2) without
crossing barriers.

And you're here to tell Koyomi the feasibility of each of his attempts.

Input

The first line of input contains three space-separated integers n, m and q (1 ≤ n, m ≤ 2 500, 1 ≤ q ≤ 100 000)
— the number of rows and columns in the grid, and the total number of Oshino and Koyomi's actions, respectively.

The following q lines each describes an action, containing five space-separated integers t, r1, c1, r2, c2 (1 ≤ t ≤ 3, 1 ≤ r1, r2 ≤ n, 1 ≤ c1, c2 ≤ m)
— the type and two coordinates of an action. Additionally, the following holds depending on the value of t:

If t = 1: 2 ≤ r1 ≤ r2 ≤ n - 1, 2 ≤ c1 ≤ c2 ≤ m - 1;

If t = 2: 2 ≤ r1 ≤ r2 ≤ n - 1, 2 ≤ c1 ≤ c2 ≤ m - 1,
the specified group of barriers exist on the ground before the removal.

If t = 3: no extra restrictions.

Output

For each of Koyomi's attempts (actions with t = 3), output one line — containing "Yes"
(without quotes) if it's feasible, and "No" (without quotes) otherwise.

Examples

input

Copy

5 6 5
1 2 2 4 5
1 3 3 3 3
3 4 4 1 1
2 2 2 4 5
3 1 1 4 4


output
No
Yes


input

Copy

2500 2500 8
1 549 1279 1263 2189
1 303 795 1888 2432
1 2227 622 2418 1161
3 771 2492 1335 1433
1 2017 2100 2408 2160
3 48 60 798 729
1 347 708 1868 792
3 1940 2080 377 1546


output
No
YesNo


Note

For the first example, the situations of Koyomi's actions are illustrated below.



题意:三种操作

1 代表以(x1,y1)为左上角的点,以(x2,y2)为右下角顶点的矩形边上画框

2.代表删去以(x1,y1)为左上角的点,以(x2,y2)为右下角顶点的矩形边上画框

3.询问点(x1,y1)是否能不通过框到达(x2,y2)

思路:

矩形内的区间更新,考虑到用二维BIT的神奇操作维护区间值,要求证明的CSDN搜索: 二维BIT更新矩阵面积

#include<bits/stdc++.h>
#define bug cout <<"bug"<<endl
using namespace std;
typedef long long ll;

const int MAX_N=2000;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;
const int seed=2333;

ll sum[2505][2505],n,m;

void add(int x,int y,ll val){ // 更新
for(int i=x;i<=2500;i+=i&(-i))
for(int j=y;j<=2500;j+=j&(-j))
sum[i][j]+=val;
// puts("**************************");
}

ll getsum(int x,int y){ // 单点求值 等价 求区间前缀和
ll res=0;
for(int i=x;i;i-=i&(-i))
for(int j=y;j;j-=j&(-j))
res+=sum[i][j];
// puts("******************");
return res;
}

void update(int x1,int y1,int x2,int y2,ll val){
add(x1,y1,val);// 结论
add(x2+1,y2+1,val);
add(x1,y2+1,-val);
add(x2+1,y1,-val);
return ;
}

int main(void){
int q;
cin >> n >> m >> q;
for(int i=1;i<=q;++i){
int op,x1,y1,x2,y2;
scanf("%d%d%d%d%d",&op,&x1,&y1,&x2,&y2);
if(op==1){
ll val = x1;
val = val*seed+y1;
val = val*seed+x2;
val = val*seed+y2;
// cout <<"v="<<val << endl;
update(x1,y1,x2,y2,val);
}
else if(op==2){
ll val = x1;
val = val*seed+y1;// 以便得知是被哪一个矩阵所套住
val = val*seed+x2;
val = val*seed+y2;
update(x1,y1,x2,y2,-val);
}
else{
if(getsum(x1,y1)==getsum(x2,y2)) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: