Skip to content

Instantly share code, notes, and snippets.

@lawrencefmm
Created May 6, 2019 22:59
Show Gist options
  • Save lawrencefmm/fed09f9963e4a287d2ebbd4177667798 to your computer and use it in GitHub Desktop.
Save lawrencefmm/fed09f9963e4a287d2ebbd4177667798 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
int n, q, pref[maxn], v[maxn];
int main()
{
ios::sync_with_stdio(false), cin.tie(nullptr);
cin >> n >> q;
for(int i = 1; i <= n; i++)
cin >> v[i];
for(int i = 1; i <= n; i++)
pref[i] = pref[i - 1] + v[i];
int total = pref[n]; // soma de todos
for(int i = 0; i < q; i++)
{
int a, b;
cin >> a >> b;
cout << total - (pref[b] - pref[a - 1]) << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment