zoukankan      html  css  js  c++  java
  • CF341D Iahub and Xors

    CF341D Iahub and Xors

    给定一个 (n imes n) 的矩阵,平面异或,求平面异或和 ((nleq10^3, mleq10^5))

    树状数组


    这里主要是记录一下板子……qaq

    时间复杂度 (O(mlog^2n))

    代码

    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    const int maxn = 1010;
    int n, m, a[maxn][maxn]; ll c[4][maxn][maxn];
    
    void upd(int x, int y, ll val) {
      int p = (x & 1) + ((y & 1) << 1);
      for (int i = x; i <= n; i += i & -i) {
        for (int j = y; j <= n; j += j & -j) {
          c[p][i][j] ^= val;
        }
      }
    }
    
    ll query(int x, int y) {
      int p = (x & 1) + ((y & 1) << 1); ll res = 0;
      for (int i = x; i; i &= i - 1) {
        for (int j = y; j; j &= j - 1) {
          res ^= c[p][i][j];
        }
      }
      return res;
    }
    
    int main() {
      scanf("%d %d", &n, &m);
      int op, x1, y1, x2, y2; ll x;
      while (m--) {
        scanf("%d %d %d %d %d", &op, &x1, &y1, &x2, &y2);
        if (op == 1) {
          printf("%lld
    ", query(x2, y2) ^ query(x1 - 1, y2) ^ query(x2, y1 - 1) ^ query(x1 - 1, y1 - 1));
        } else {
          scanf("%lld", &x);
          upd(x1, y1, x), upd(x2 + 1, y1, x), upd(x1, y2 + 1, x), upd(x2 + 1, y2 + 1, x);
        }
      }
      return 0;
    }
    
  • 相关阅读:
    typeof用法
    图片上传显示图片
    用Express 创建项目
    Express中使用session
    生成一个node项目
    async同步异步
    async异步流程控制
    nodejs并行无关联
    nodejs串行有关联
    nodejs串行无关联
  • 原文地址:https://www.cnblogs.com/Juanzhang/p/10345444.html
Copyright © 2011-2022 走看看