Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <cmath>
- #include <map>
- #include <cstring>
- using namespace std;
- vector<long long> prefix_sum;
- long long query(int a, int b) {
- if(a == 0) {
- return prefix_sum[b];
- }
- return prefix_sum[b] - prefix_sum[a - 1];
- }
- int main() {
- int n, q;
- cin >> n >> q;
- vector<int> v(n);
- long long sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- sum += v[i];
- prefix_sum.push_back(sum);
- }
- for(int i = 0; i < q; i++) {
- int a, b;
- cin >> a >> b;
- a--;
- b--;
- cout << query(a, b) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement