zoukankan      html  css  js  c++  java
  • Mobile phones POJ

    原题链接

    • 题解:二维树状数组,第一次遇见,就是快速的计算出前缀和。
    • 代码:
    #include <cstdio>
    #include <iostream>
    #include <queue>
    #include <cstring>
    #include <vector>
    #include <algorithm>
    #include <cmath>
    #include <map>
    using namespace std;
    typedef long long ll;
    const ll inf = 0x3f3f3f3f;
    const ll N = 1333;
    int n;
    struct BIT {
        ll d[N][N];
        inline ll lowbit(ll x) {return -x&x;}
        void add (int x, int y, ll k) {
            for (int i = x; i <= n; i += lowbit(i)) {
                for (int j = y; j  <= n; j += lowbit(j)) {
                    d[i][j] +=k;
                }
            }
        }
        ll ask(int x, int y) {
            ll ret = 0;
            for (int I = x; I >0; I -= lowbit(I)) {
                for (int J = y; J > 0; J -= lowbit(J)) {
                    ret += d[I][J];
                }
            }
            return ret;
        }
    }T;
    signed main() {
        scanf("%d%d", &n, &n);
        n++;
        int op;
        while (~scanf("%d", &op)) {
            if (op == 3)break;
            else if (op == 2) {
                int x1, y1, x2, y2;
    
                scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
                x1 ++,y1++,x2++,y2++;
                printf("%lld
    ", T.ask(x2, y2) - T.ask(x1-1, y2) - T.ask(x2, y1-1) + T.ask(x1-1, y1-1));
            }
            else if (op == 1) {
                int x, y, k;
                scanf("%d%d%d", &x, &y, &k);
                x++,y++;
                T.add(x, y, k);
               // cout << T.ask(x, y) << endl;
            }
        }
    }
    
    
  • 相关阅读:
    浅谈React数据流管理
    Nodejs相关知识
    React其它相关知识点
    React-Native知识点相关
    React状态管理相关
    React设计模式相关
    Node.js调试相关
    Event loop详解(包含Node端)
    JS this详解
    Babel知识点相关
  • 原文地址:https://www.cnblogs.com/Xiao-yan/p/14693422.html
Copyright © 2011-2022 走看看