-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKuriyamaStones.cpp
More file actions
52 lines (43 loc) · 1009 Bytes
/
KuriyamaStones.cpp
File metadata and controls
52 lines (43 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define ii pair<int, int>
int main(){
ios_base::sync_with_stdio(false);cin.tie(nullptr);
int n;
cin >> n;
vector <ll> arr(n);
for(int i=0; i<n; i++){
cin >> arr[i];
}
vector <ll> brr(n);
brr = arr;
sort(brr.begin(), brr.end());
for(int i=1; i<n; i++){
arr[i] += arr[i-1];
}
for(int i=1; i<n; i++){
brr[i] += brr[i-1];
}
int q;
cin >> q;
while(q--){
int a, b, c;
cin >> a >> b >> c;
if(a == 1){
if(b == 1){
cout << arr[c-1] << "\n";
}else{
cout << arr[c-1] - arr[b-2] << endl;
}
} else {
if(b == 1){
cout << brr[c-1] << "\n";
}else{
cout << brr[c-1] - brr[b-2] << endl;
}
}
}
return 0;
}