AcWing 4789. 前缀和序列
原题链接
中等
作者:
别期待太多
,
2024-07-24 19:10:45
,
所有人可见
,
阅读 2
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N = 100010;
int a[N];
long long Sa[N], Sb[N];
int main()
{
int n, m;
scanf("%d",&n);
for(int i = 1; i <= n; i ++)
{
scanf("%d", &a[i]);
Sa[i] = Sa[i-1] + a[i];//排序之前的
}
sort(a+1, a+n+1);
for(int i = 1; i <= n; i++)
Sb[i] = Sb[i-1] + a[i];//排序之后的
scanf("%d",&m);
while(m --)
{
int choice, l, r;
scanf("%d%d%d",&choice, &l, &r);
if(choice == 1)
printf("%lld\n",Sa[r] - Sa[l-1]);
else
printf("%lld\n",Sb[r] - Sb[l-1]);
}
return 0;
}