range queries and one graph

This commit is contained in:
2024-06-15 11:50:15 +02:00
parent b67bf7bbea
commit 93ad8c5841
13 changed files with 288 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
// Static Range Sum Queries
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n, q; cin >> n >> q;
vector<ll> pref(n, 0);
ll x; cin >> x;
pref[0] = x;
for (int i = 1; i < n; i ++) {
ll y; cin >> y;
pref[i] = y + pref[i-1];
}
for (int i{}; i < q; i++) {
int a, b; cin >> a >> b;
if (a >= 2 ) cout << pref[b - 1] - pref[a - 2] << endl;
else cout << pref[b - 1] << endl;
}
return 0;
}