Codeforces (869E || #439 Div.2 E || #439 Div.1 C)

Description

biu~
给一个方格图,支持以下操作:

  1. 在一个子矩形外围套一圈栅栏。
  2. 去掉一个子矩形外围的栅栏(保证存在)。
  3. 询问从\((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;
}

转载于:https://www.cnblogs.com/aziint/p/8416185.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值