fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n;cin>>n;
  6. vector<int>v(n);
  7. for(int i=0;i<n;i++){
  8. cin>>v[i];
  9. if(i!=0){
  10. v[i]+=v[i-1];
  11. }
  12. }
  13. int q;cin>>q;
  14. while(q--){
  15. int s,e;cin>>s>>e;
  16. if(s!=0){
  17. cout<<"ANS:"<<v[e]-v[s-1]<<endl;
  18. }else{
  19. cout<<"ANS:"<<v[e]<<endl;
  20. }
  21. }
  22.  
  23. }
Success #stdin #stdout 0s 5320KB
stdin
3
1 4 1
3
1 1
1 2
0 2
stdout
ANS:4
ANS:5
ANS:6