fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. // ????????? ??????????? ????? ? ??????
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(NULL);
  10.  
  11. int n;
  12. if (!(cin >> n)) return 0;
  13.  
  14. // ????????? long long ?? ???? ?? ????? ??????, ???? ?? ???? ??????? ????
  15. vector<long long> prefix_sum(n);
  16. long long current_sum = 0;
  17.  
  18. for (int i = 0; i < n; i++) {
  19. int earning;
  20. cin >> earning;
  21. current_sum += earning;
  22. prefix_sum[i] = current_sum;
  23. }
  24.  
  25. int m;
  26. cin >> m;
  27. while (m--) {
  28. int a, b;
  29. cin >> a >> b;
  30.  
  31. if (a == 0) {
  32. cout << prefix_sum[b] << "\n";
  33. } else {
  34. cout << prefix_sum[b] - prefix_sum[a - 1] << "\n";
  35. }
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty