Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
1.7 kB
2
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
 #define ll long long
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define nn "\n"
#define ex exit(0);
#define sz(s) (int)(s).size()
int n  ,a  , b  , t ;
const int N = 1e6;
int  q[N];
ll bit , k   , res   , ans  , cnt , sum = 0   ;
ll  y    ;
char pp[21][21];
ll lcm(ll x , ll y ){
    return x/__gcd(x , y )*y;
}
bool check(ll x , ll w , ll h , int n ){
    if(x/w>=n || x/h>=n){
        return 1 ;
    }
    if(x/w*x/h>=n){
        return 1;
    }
    else return 0;
}
const int K  = 1e6;
int s[100];
void build(int v , int l , int  r ){
    if(l==r){
        s[v] = q[l];
    }
    else {
        int m = (l+r)/2;
        build(v*2 , l , m );
        build(v*2+1 , m+1 , r);
        s[v]=  s[v*2]+s[v*2+1];
    }
}
int get(int v , int tl , int tr , int l , int r ) {
    if (tl <= l && r <= tr) {
        return s[v];
    }
    if (l > tr || r < tl) {
        return 0;
    } else {
        int m = (l + r) / 2;
        return get(v * 2, tl, tr, l, m) + get(v * 2 + 1, tl, tr, m + 1, r);
    }
}
int bp(int x , int l , int r ){

}
int main() {
    //freopen("sum2.in" , "r", stdin);
    //freopen("sum2.out" , "w" , stdout);
    cin>> n >> t ;
    for(int i= 1 ; i <= n ; i++){
        cin>> q[i];
    }
    build(1 , 1 , n );
    int c, l , r ;
    for(int i =0 ; i < t ; i++){
        cin>> c >> l >> r;
        l++;
        if(c==1){

        }
        else {
            cout << get( 1 , l , r  , 1 , n )<< ' ';
        }
    }
}
//Life is good
//aza genius machine nomer1=sigma
//Azamat lox mal chort
//Azamat medium