fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. int n,m;
  5. cin>>n>>m;
  6. int a[n+1];
  7. long long pr[n+2]={0,};
  8. for(int i=1; i<=n; i++)
  9. cin>>a[i];
  10. for(int i=1; i<=n; i++)
  11. pr[i]=pr[i-1]+a[i];
  12. for(int i=1; i<=n; i++){
  13. int x,y;
  14. cin>>x>>y;
  15. cout<<pr[y]+pr[x-1]<<endl;
  16. }
  17. }
Success #stdin #stdout 0.01s 5264KB
stdin
5 2
1 2 3 4 5
2 4
3 5
5 2
1 2 3 4 5
2 4
3 5
5 2
1 2 3 4 5
2 4
3 5
5 2
1 2 3 4 5
2 4
3 5
5 2
1 2 3 4 5
2 4
3 5
stdout
11
18
13
3
13