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