Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 题目中虽然说修改值c不超过1w，但是必须要用long long 否则就wa

Posted by 3017218189 at 2020-08-09 16:01:36 on Problem 3468
```附赠一个树状数组代码，非常简陋，请见谅
#include<iostream>
#include<cstdio>
using namespace std;
int n;
const int maxn = 1e6+50;
long long bit[maxn];//差分
long long bit2[maxn];// bit2[i] = i*bit[i]
void add(int i,long long x) {
int p = i;
while(i<=n) {
bit[i]  +=x;
bit2[i] +=p*x;
i+= i&(-i);
}
}
void modify(int l,int r,long long k){
}
long long sum(int i) {
int p = i;
long long ans=0;
while(i>0) {
ans += (p+1)*bit[i] -bit2[i];
i-=i&(-i);
}
return ans;
}
return sum(r) - sum(l-1);
}
int main() {
int m;
scanf("%d%d",&n,&m);
int before = 0;
for(int i=1; i<=n; ++i) {
int t ;
scanf("%d",&t);
before = t;
}
char input[5];
while(m--){
scanf("%s",input);
if(input[0]=='Q'){
int a;
int b;
scanf("%d%d",&a,&b);
printf("%lld\n",ans);
}else{
int a;
int b;
long long c;
scanf("%d%d%lld",&a,&b,&c);
modify(a,b,c);
}
}
return 0;
}
```

Followed by: