fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define el "\n"
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define se second
  7. #define fi first
  8. #define be begin()
  9. #define en end()
  10. #define Faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
  11. int main()
  12. {
  13. Faster;
  14. int n; cin >> n;
  15. ll a[n + 1];
  16. a[0] = 0;
  17. for(int i = 1; i <= n; i++)
  18. {
  19. cin >> a[i];
  20. a[i] = a[i] + a[i-1];
  21. }
  22. int q; cin >> q;
  23. while(q--)
  24. {
  25. int i, j;
  26. cin >> i >> j;
  27. cout << a[j + 1] - a[i] << el;
  28. }
  29.  
  30. }
  31.  
Success #stdin #stdout 0s 5284KB
stdin
5
1 2 3 4 5
2
0 4
1 3
stdout
15
9