zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    POJ 1953 World Cup Noise
    POJ 1995 Raising Modulo Numbers (快速幂取余)
    poj 1256 Anagram
    POJ 1218 THE DRUNK JAILER
    POJ 1316 Self Numbers
    POJ 1663 Number Steps
    POJ 1664 放苹果
    如何查看DIV被设置什么CSS样式
    独行DIV自适应宽度布局CSS实例与扩大应用范围
    python 从入门到精通教程一:[1]Hello,world!
  • 原文地址:https://www.cnblogs.com/aziint/p/8416185.html
Copyright © 2011-2022 走看看