Josif_tepe

Untitled

Jan 29th, 2026
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <queue>
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8.     int n;
  9.     cin >> n;
  10.    
  11.     vector<int> v(n);
  12.     vector<int> pref_sum(n);
  13.    
  14.     int sum = 0;
  15.     for(int i = 0; i < n; i++) {
  16.         cin >> v[i];
  17.        
  18.         sum += v[i];
  19.         pref_sum[i] = sum;
  20.     }
  21.    
  22.     int q;
  23.     cin >> q;
  24.    
  25.     for(int i = 0; i < q; i++) {
  26.         int x, y;
  27.         cin >> x >> y;
  28.        
  29.         if(x == 0) {
  30.             cout << pref_sum[y] << endl;
  31.         }
  32.         else {
  33.             cout << pref_sum[y] - pref_sum[x - 1] << endl;
  34.         }
  35.     }
  36.    
  37.    
  38.    
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment