Created
June 4, 2019 18:11
-
-
Save Thiago4532/609d652282edcd7ac3c0ea3cf1245405 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
// Ideias 06 - Soma de Prefixos | |
// Thiago Mota | |
#include <bits/stdc++.h> | |
using namespace std; | |
const int maxn = 100010; | |
int n, q, v[maxn]; | |
int main() { | |
cin >> n >> q; | |
for(int i = 1; i <= n; i++) { | |
cin >> v[i]; // Lendo o vetor | |
} | |
for(int i = 1; i <= q; i++) { | |
int l, r; | |
cin >> l >> r; | |
int soma = 0; | |
for(int j = l; j <= r; j++) | |
soma += v[j]; // Somando cada elemento de [l, r] | |
cout << soma << "\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment