AcWing 4789. 前缀和序列
原题链接
中等
作者:
馍高一丈
,
2024-10-02 19:44:30
,
所有人可见
,
阅读 1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
LL a[N], sum_a[N], b[N], sum_b[N];
int main(){
int n, m;
cin >> n;
for (int i = 1; i <= n; i ++){
scanf("%Ld", &a[i]);
sum_a[i] = sum_a[i - 1] + a[i];
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i ++) sum_b[i] = sum_b[i - 1] + a[i];
cin >> m;
while(m --){
int k, l, r;
cin >> k >> l >> r;
if (k == 1) printf("%Ld\n", sum_a[r] - sum_a[l - 1]);
else printf("%Ld\n", sum_b[r] - sum_b[l - 1]);
}
return 0;
}