https://vjudge.net/problem/POJ-3468
样例过了,交上去WA
CODE:
#include <iostream>
#include <stdio.h>
using namespace std;
inline long long read(){
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9'){
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9'){
x = x * 10 + ch - 48;
ch = getchar();
}
return x * f;
}
int a[100010];
long long d1[100010], d2[100010];
long long n, m;
int lowbit(int x){
return x & (-x);
}
void add(int x, int k){
for(int i = x;i <= n;i += lowbit(i)){
d1[i] += k;
d2[i] += k * (x - 1);
}
}
long long sum(int x){
long long tot = 0;
for(int i = x;i > 0;i -= lowbit(i))
tot = tot + x * d1[i] - d2[i];
return tot;
}
int main(){
n = read();
m = read();
for(long long i = 1;i <= n;i++){
a[i] = read();
int p = a[i] - a[i - 1];
add(i, p);
}
for(long long i = 1;i <= m;i++){
char ch;
int x, y, z;
cin >> ch;
if(ch == 'Q'){
x = read();
y = read();
cout << sum(y) - sum(x - 1) << endl;
}
else{
x = read();
y = read();
z = read();
add(x, z);
add(y + 1, -z);
}
}
return 0;
}
求助,急