Skip to content

Instantly share code, notes, and snippets.

@Thiago4532
Created June 4, 2019 18:11
Show Gist options
  • Save Thiago4532/609d652282edcd7ac3c0ea3cf1245405 to your computer and use it in GitHub Desktop.
Save Thiago4532/609d652282edcd7ac3c0ea3cf1245405 to your computer and use it in GitHub Desktop.
// 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