首页 > 其他 > 详细

P2068 统计和

时间:2019-03-04 23:37:53      阅读:196      评论:0      收藏:0      [点我收藏+]

P2068 统计和

这题真的非常水了

如果不会 右转【模板】树状数组 2

基本上是一模一样的

#include <bits/stdc++.h>
#define lowbit(x) x&-x
using namespace std ;
typedef long long LL;
inline LL read(){ LL x=0; int f=1; char ch=getchar();
    while(!isdigit(ch)) { if (ch==-) f=-1; ch=getchar(); }
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); return x*f;
}
int n,m;
int tree[2000000+10];
inline void add (int x, int k){
    while (x<=n) tree[x]+=k,x+=lowbit(x);
    return ;
}
inline LL sum ( int x ){
    LL ans = 0;
    while (x) {
        ans += tree [x] ;
        x -= lowbit(x);
    }
    return ans ;
}
signed main() {
    n=read() , m=read ();
    for(register int i=1;i<=m;i++) {
        char x;
        cin>>x;
        int y=read() , z=read();
        if (x == x) add(y , z);
        if (x == y) cout << sum (z) - sum (y - 1) <<endl ;
    }
    return 0;
}

 

P2068 统计和

原文:https://www.cnblogs.com/qf-breeze/p/10474095.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!