Codeforces (869E || #439 Div.2 E || #439 Div.1 C)
Description
biu~
给一个方格图,支持以下操作:
- 在一个子矩形外围套一圈栅栏。
- 去掉一个子矩形外围的栅栏(保证存在)。
- 询问从\((x1, y1)\)到\((x2, y2)\)是否可以不穿过栅栏
保证栅栏间无交,无重边,无共点,且和边界不交。
\(r, c \leqslant 2500\), \(q \leqslant 100000\)。
Solution
每一“层”haxh不同的值,二维BIT维护,判断两点的值是否相等即可。
#include<bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, flag = 1; char ch = getchar();
while (ch > '9' || ch < '0') { if (ch == '-') flag = -1; ch = getchar(); }
while (ch <= '9' && ch >= '0') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * flag;
}
#define N 2550
#define ll long long
const ll hashValue = 817;
int n, m;
struct BITType {
ll c[N][N];
inline int lowbit(int k) { return (k & (-k)); }
void add(int i, int j, ll delta) {
for (int x = i; x <= n; x += lowbit(x)) for (int y = j; y <= m; y += lowbit(y))
c[x][y] += delta;
}
ll query(int i, int j) {
ll ans = 0;
for (int x = i; x; x -= lowbit(x)) for (int y = j; y; y -= lowbit(y)) ans += c[x][y];
return ans;
}
void update(int r1, int c1, int r2, int c2, ll x) {
add(r1, c1, x), add(r1, c2 + 1, -x),
add(r2 + 1, c1, -x), add(r2 + 1, c2 + 1, x);
}
}bit;
int main() {
cin >> n >> m; int q = read();
while (q--) {
int op = read();
int r1 = read(), c1 = read(), r2 = read(), c2 = read();
if (op != 3) {
ll x = r1; (x *= hashValue) += c1; (x *= hashValue) += r2; (x *= hashValue) += c2;
if (op == 2) x *= -1;
bit.update(r1, c1, r2, c2, x);
}
else puts(bit.query(r1, c1) == bit.query(r2, c2) ? "Yes" : "No");
}
return 0;
}