Skip to content

Commit b7b09f4

Browse files
committed
upload files
1 parent 96e3c1a commit b7b09f4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

StaticQueries/RangeSumQueries.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//Friday 12-November-2021 17:41:00
2+
#include <bits/stdc++.h>
3+
//@ReetuRaj77
4+
#define lli long long int
5+
#define ulli unsigned long long int
6+
7+
#define all(x) (x).begin(),(x).end()
8+
9+
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr)
10+
11+
using namespace std;
12+
13+
14+
int main() {
15+
int n, q;
16+
cin >> n >> q;
17+
vector<lli>a(n);
18+
for (auto&x : a)cin >> x;
19+
vector<lli>prefix(n + 1);
20+
prefix[0] = a[0];
21+
for (int i = 1; i < n; i++)
22+
prefix[i] = prefix[i - 1] + a[i];
23+
24+
for (int i = 0; i < q; i++) {
25+
int x, y;
26+
cin >> x >> y;
27+
x--, y--;
28+
if (x == 0)cout << prefix[y] << endl;
29+
else cout << prefix[y] - prefix[x-1] << endl;
30+
}
31+
return 0;
32+
}

0 commit comments

Comments
 (0)