fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 1e5 + 5;
  4. int n, q;
  5. int a[maxn], pre[maxn];
  6.  
  7.  
  8. int main(){
  9. cin >> n >> q;
  10. for (int i = 1; i <= n; i++) {
  11. cin >> a[i];
  12. }
  13.  
  14. for (int i = 1; i <= n ; ++i) {
  15. pre[i] = pre[i-1] + a[i];
  16. }
  17.  
  18.  
  19. for (int i = 1; i <= q ; ++i) {
  20. int l, r; cin >> l >> r;
  21. cout << pre[r] - pre[l-1] << '\n';
  22. }
  23.  
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
Standard output is empty