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 3258 二分答案
    Prototype 模式示例代码 (C++)
    offsetof 和 container_of
    二进制整数中的“1”
    Binary Tree Traversal Algorithms (二叉树遍历算法)
    A* Pathfinding Algorithm
    Axis­ Aligned 
Rectangles (Google 面试题, 2016网易游戏校招笔试)
    [LeetCode] Burst Ballons
    C++ 继承语义下构造函数中的对象指针
    kill-9和kill-15的区别
  • 原文地址:https://www.cnblogs.com/aziint/p/8416185.html
Copyright © 2011-2022 走看看