range queries and one graph
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user