Created
May 6, 2019 22:59
-
-
Save lawrencefmm/fed09f9963e4a287d2ebbd4177667798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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