51Nod 1081前缀和

 

 

#include <iostream>  
#include <stdio.h>  
using namespace std;  
  
long long a[50005];  
long long sum[50005];  
int main()  
{  
    int n;  
    cin>>n;  
    for(int i=1;i<=n;i++)  
    {  
        cin>>a[i];  
        sum[i]=sum[i-1]+a[i];  
    }  
    int q;  
    cin>>q;  
    while(q--)  
    {  
        int x,y;  
        cin>>x>>y;  
        cout<<sum[x+y-1]-sum[x]+a[x] <<endl;  
    }  
    return 0;  
}  

 

posted @ 2017-07-20 23:43  kimsimple  阅读(111)  评论(0编辑  收藏  举报