Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
877 B
2
Indexable
Never
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"

const long long N = (2 * 1e5) + 10;
long long arr[N];
long long sum[N];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long n;
    cin >> n;

    for(long long i=1;i<=n;i++){

        cin >> arr[i];

    }

    reverse(arr+1,arr+n+1);

    for(long long i=1;i<N;i++){
        sum[i] = sum[i-1] + arr[i];
    }

    long long Q;
    cin >> Q;
    long long b;

    while(Q--){

        cin >> b;

        if(b==1){
            long long l,r;
            cin >> l >> r;
            cout << sum[n-l+1] - sum[n-r] << endl;
        }
        else if(b==2){

            long long c;
            cin >> c;
            arr[n+1] = c;
            sum[n+1] = sum[n] + arr[n+1];
            n++;
        }
    }


    return 0;

}