4789. 前缀和序列
作者:
梦昉
,
2024-04-07 23:26:11
,
所有人可见
,
阅读 7
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int N = 1e5+10;
ll a[N],b[N];
ll m,n,l,r,k;
void emerge(ll x[])
{
for(int i = 1; i <= n; i ++) x[i] += x[i-1];
}
int main()
{
cin>>n;
b[0] = 0;
for(int i = 1; i <= n; i ++) cin>>a[i], b[i] = a[i];
sort(b+1,b+n+1);
emerge(a),emerge(b);
cin>>m;
while(m --)
{
cin>>k>>l>>r;
if(k == 1) cout<<(ll)(a[r] - a[l-1])<<endl;
else cout<<(ll)(b[r] - b[l-1])<<endl;
}
return 0;
}