fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int N = 5e5 + 5;
  5. long long n, q, l, r, a[N], pref[N];
  6.  
  7. int main()
  8. {
  9. ios_base::sync_with_stdio(false);
  10. cin.tie(0);
  11. cout.tie(0);
  12. // freopen(".inp", "r", stdin);
  13. // freopen(".out", "w", stdout);
  14. cin >> n >> q;
  15. for(int i=1; i<=n; ++i) {
  16. cin >> a[i];
  17. pref[i] = pref[i-1] + a[i];
  18. }
  19. while(q--) {
  20. cin >> l >> r;
  21. cout << pref[r] - pref[l] << '\n';
  22. }
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty