fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. unsigned long long int T, n, q, ival, jval, tmp;
  7.  
  8. int main() {
  9.  
  10. cin.tie(0); ios_base::sync_with_stdio(false);
  11.  
  12. cin >> T;
  13. while (T--) {
  14.  
  15. cin >> n >> q;
  16.  
  17. vector<unsigned long long int> arr(n, 0);
  18.  
  19. cin >> tmp;
  20. arr[0] = tmp;
  21.  
  22. for (int i = 1; i < n; i++) {
  23. cin >> tmp;
  24. arr[i] = arr[i - 1] + tmp;
  25. }
  26.  
  27. while (q--) {
  28. cin >> ival >> jval;
  29. cout << arr[jval] - arr[ival] << "\n";
  30. }
  31. cout << "\n";
  32. }
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 3464KB
stdin
2

5 2
1 2 3 4 5
4 4
0 3

10 5
10 9 7 20 14 23 14 27 38 77
8 9
7 9
6 9
5 9
4 9
stdout
0
9

77
115
142
156
179