zoukankan      html  css  js  c++  java
  • CF198 div1 D

    简单说就是左边x,y按照奇偶分为四种对于答案的影响都是不相关的

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int MAXN = 1e3+5;
    int N,M;
    ll tree[4][MAXN][MAXN];
    
    int ju(int x, int y) {
        int tt = 0;
        if(x%2) tt ++;
        if(y%2) tt += 2;
        return tt;
    }
    void Update(int x,int y, ll v) {
        int ty = ju(x,y);
        for(int i = x; i <= N; i += i&-i)
            for(int j = y; j <= N; j += j&-j)
                tree[ty][i][j] ^= v;
    } 
    ll Sum(int x,int y) {
        int ty = ju(x,y);
        ll ans = 0;
        for(int i = x; i > 0; i -= i&-i)
            for(int j = y; j > 0; j -= j&-j)
                ans ^= tree[ty][i][j];
        return ans;
    }
    
    int main(){
        while(~scanf("%d %d",&N,&M)) {
            memset(tree ,0, sizeof(tree));
    
            for(int i = 1; i <= M; ++i) {
                int a,b,c,d; int ty; ll v;
                scanf("%d",&ty);
                if(ty == 2) {
                    scanf("%d %d %d %d %lld",&a,&b,&c,&d,&v);
                    Update(a,b,v); 
                    Update(c+1,b,v);
                    Update(a,d+1,v);
                    Update(c+1,d+1,v);  
                }else {
                    ll ans = 0;
                    scanf("%d %d %d %d",&a,&b,&c,&d);
                    ans ^= Sum(c,d);
                    ans ^= Sum(a-1,d);
                    ans ^= Sum(c,b-1);
                    ans ^= Sum(a-1,b-1);
                    printf("%lld
    ",ans);
                }
            }
        }
        return 0;   
    }
    
  • 相关阅读:
    Java Web前后端分离的思考与实践
    JDBC剖析篇(1):java中的Class.forName()
    UVa1471
    Uva11572
    Uva11134
    Uva10755
    Floyd判圈法
    Java泛型-通配符的上限和下限问题
    Codeforces 384E-线段树+dfs序
    codeforcesRound378C-dfs+树状数组
  • 原文地址:https://www.cnblogs.com/Basasuya/p/8433750.html
Copyright © 2011-2022 走看看