• POJ 1195


    #include <iostream>
    #define MAXN 1100
    using namespace std;
    
    long _m[MAXN][MAXN];//C数组
    
    int n;
    
    void init();
    long Lowbit(int t);
    long sum_b_e(int x,int y);
    void plus(int x,int y,long num);
    long give_place(int i,int j);
    long square;
    
    int main()
    {
        //freopen("acm.acm","r",stdin);
        int num_0;
        int i;
        int j;
        int x;
        int y;
        int _x;
        int _y;
        int a;
        int _b;
        int _e;
        int ins;
        scanf("%d",&num_0);
        scanf("%d",&square);
        n = square;
        while(scanf("%d",&ins))
        {
            if(ins == 1)
            {
                scanf("%d%d%d",&x,&y,&a);
                ++ x;
                ++ y;
    
                plus(x,y,a);
            }
            else if(ins == 2)
            {
                scanf("%d%d%d%d",&x,&y,&_x,&_y);
                ++ x;
                ++ y;
                ++_x;
                ++_y;
                cout<<sum_b_e(_x,_y) + sum_b_e(x-1,y-1) - sum_b_e(_x,y-1) - sum_b_e(x-1,_y)<<endl;
            }
            else if(ins == 3)
            {
                break;
            }
        }
        
    }
    
    
    long Lowbit(int t) 
    { 
        return t & (t^(t - 1)); 
    }
    
    
    long sum_b_e(int x,int y) 
    { 
        long sum = 0; 
        int i;
        int j;
        for(i = x; i >= 1; i -= Lowbit(i))
        {
            for(j = y; j >= 1; j -= Lowbit(j))
            { 
                sum += _m[i][j];
            }
        } 
        return sum; 
    }
    
    void plus(int x,int y,long num) 
    { 
        int i;
        int j;
        for(i = x; i <= n; i += Lowbit(i))
        {
            for(j = y; j <= n; j += Lowbit(j))
            { 
                 _m[i][j] += num; 
            } 
        }
    } 

    关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

    技术网站地址: vmfor.com

  • 相关阅读:
    HNOI 越狱
    中国剩余定理详解
    洛谷P1133 教主的花园
    poj2728 Desert King
    bzoj1503 郁闷的出纳员
    Code Forces 698A Vacations
    Loj 10211 sumdiv
    noip2010 乌龟棋
    洛谷P4141消失之物
    Code Forces 543A Writing Code
  • 原文地址:https://www.cnblogs.com/gavinsp/p/4563329.html
Copyright © 2020-2023  润新知