论树状数组与线段树的博(dui)弈(gang)
动态的修改求和
(zi)(cheng)万能的线段树(肯定不是我说的,但是和天勇勋押韵。。。)
所以,题目来源:http://cojs.tk/cogs/problem/problem.php?pid=36
还有我的代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
long long yy[10010],sum[10010];
int main(){
freopen("sum.in","r",stdin);
freopen("sum.out","w",stdout);
long long n;
cin>>n;
for(long long i=1;i<=n;i++){
cin>>yy[i];
sum[i]=sum[i-1] + yy[i];
}
long long m;
cin>>m;
long long a,b;
for(long long i=1;i<=m;i++){
scanf("%d%d",&a,&b);
printf("%lld\n", sum[b]-sum[a-1]);
}
return(0);
}
线段树做法参考友链:http://tyswly.com/