FEgor04

Untitled

Sep 7th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #pragma GCC target ("avx2")
  4. #pragma GCC optimization ("O3")
  5. #pragma GCC optimization ("unroll-loops")
  6.  
  7. int main() {
  8.     // ios_base::sync_with_stdio(0);
  9.     // cin.tie(NULL);
  10.     freopen("rsq.in", "r", stdin);
  11.     freopen("rsq.out", "w", stdout);
  12.     int n, m, temp;
  13.     cin >> n >> m;
  14.     vector<int> arr(n+1, 0);
  15.     for(int i = 1; i <= n; i++) {
  16.         cin >> temp;
  17.         arr[i] = arr[i-1] + temp;
  18.         // cout << "temp is " << temp << "\narr[i] is " << arr[i] << "\ni is " << i << "\n\n";
  19.     }
  20.     int l, r;
  21.     for(int i = 0; i < m; i++) {
  22.         cin >> l >> r;
  23.         // cout << i << "\n";
  24.         // cout << arr[l] << "\t\t" << arr[r] << "\n\n";
  25.         cout << arr[r] - arr[l-1] << "\n";
  26.     }
  27.     return 0;
  28. }
Add Comment
Please, Sign In to add comment