#line 2 "library/template/template.hpp" //#pragma GCC target("avx") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include #define overload4(a,b,c,d,e,...) e #define overload3(a,b,c,d,...) d #define rep1(a) for(ll i=0;i<(ll)(a);i++) #define rep2(i,a) for(ll i=0;i<(ll)(a);i++) #define rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++) #define rep4(i,a,b,c) for(ll i=(ll)(a);i<(ll)(b);i+=(ll)(c)) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep1(a) for(ll i=(ll)(a)-1;i>=0;i--) #define rrep2(i,a) for(ll i=(ll)(a)-1;i>=0;i--) #define rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--) #define rrep(...) overload3(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__) #define fore(...) for (auto&& __VA_ARGS__) #define all1(i) begin(i),end(i) #define all2(i,a) begin(i),begin(i)+a #define all3(i,a,b) begin(i)+a,begin(i)+b #define all(...) overload3(__VA_ARGS__,all3,all2,all1)(__VA_ARGS__) #define rall(n) (n).rbegin(),(n).rend() #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) #define pb push_back #define eb emplace_back #define END(...) {print(__VA_ARGS__);return;} using namespace std; using ll=long long; using ull=unsigned long long; using ld=long double; using vl=vector; using vi=vector; using vs=vector; using vc=vector; using vvl=vector; using pi=pair; using pl=pair; using vvc=vector; using vd=vector; using vp=vector; using vb=vector; constexpr int dx[8]={1,0,-1,0,1,-1,-1,1}; constexpr int dy[8]={0,1,0,-1,1,1,-1,-1}; constexpr ll MOD=1000000007; constexpr ll mod=998244353; constexpr ld EPS=1e-8; constexpr ld PI=3.1415926535897932384626; template ostream &operator<<(ostream&os,const pair&p){os< istream &operator>>(istream&is,pair&p){is>>p.first>>p.second;return is;} template ostream &operator<<(ostream&os,const vector&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"");}return os;} template istream &operator>>(istream&is,vector&v){for(T &in:v){is>>in;}return is;} void scan(){} template void scan(Head&head,Tail&... tail){cin>>head;scan(tail...);} template void print(const T &t){cout< void print(const Head &head, const Tail &... tail){cout< void fin(const T &... a){print(a...);exit(0);} template inline bool chmax(T&a,U b){return a inline bool chmin(T&a,U b){return a>b&&(a=b,true);} template class infinity{ public: static constexpr T MAX=numeric_limits::max(); static constexpr T MIN=numeric_limits::min(); static constexpr T value=numeric_limits::max()/2; static constexpr T mvalue=numeric_limits::min()/2; }; #if __cplusplus <= 201402L templateconstexpr T infinity::value; templateconstexpr T infinity::mvalue; templateconstexpr T infinity::MAX; templateconstexpr T infinity::MIN; #endif templateconstexpr T INF=infinity::value; constexpr long long inf=INF; inline int popcnt(ull x){ #if __cplusplus>=202002L return popcount(x); #endif x=(x&0x5555555555555555)+((x>>1)&0x5555555555555555);x=(x&0x3333333333333333)+((x>>2)&0x3333333333333333);x=(x&0x0f0f0f0f0f0f0f0f)+((x>>4)&0x0f0f0f0f0f0f0f0f);x=(x&0x00ff00ff00ff00ff)+((x>>8)&0x00ff00ff00ff00ff);x=(x&0x0000ffff0000ffff)+((x>>16)&0x0000ffff0000ffff);return (x&0x00000000ffffffff)+((x>>32)&0x00000000ffffffff); } template struct is_specialize:false_type{}; template struct is_specialize::type>:true_type{}; template struct is_specialize::type>:true_type{}; template struct is_specialize::value,void>>:true_type{}; void dump(const char&t){cerr<::value,nullptr_t> =nullptr> void dump(const T&t){cerr< void dump(const T&t,enable_if_t::value>* =nullptr){string tmp;if(t==infinity::value||t==infinity::MAX)tmp="inf";if(is_signed::value&&(t==infinity::mvalue||t==infinity::MIN))tmp="-inf";if(tmp.empty())tmp=to_string(t);cerr< void dump(const pair&); template void dump(const T&t,enable_if_t::value>* =nullptr){cerr<<"{";for(auto it=t.begin();it!=t.end();){dump(*it);cerr<<(++it==t.end()?"":",");}cerr<<"}";} template void dump(const pair&t){cerr<<"(";dump(t.first);cerr<<",";dump(t.second);cerr<<")";} void trace(){cerr< void trace(Head&&head,Tail&&... tail){dump(head);if(sizeof...(tail))cerr<<",";trace(forward(tail)...);} #ifdef ONLINE_JUDGE #define debug(...) (void(0)) #else #define debug(...) do{cerr<<#__VA_ARGS__<<"=";trace(__VA_ARGS__);}while(0) #endif struct IOSetup{IOSetup(){cin.tie(nullptr);ios::sync_with_stdio(false);cout.tie(0);cout<struct REC{F f;REC(F&&f_):f(std::forward(f_)){}templateauto operator()(Args&&...args)const{return f(*this, std::forward(args)...);}}; /** * @brief Template(テンプレート) */ #line 2 "code.cpp" template struct dynamic_segtree{ public: dynamic_segtree():dynamic_segtree(numeric_limits::max()>>1){} dynamic_segtree(long long n):n(n),root(nullptr){} void set(int p,const S&x){inner_set(root,0,n,p,x);} S get(long long p)const{return inner_get(root,0,n,p);} S operator[](long long p)const{return inner_get(root,0,n,p);} S query(long long l,long long r)const{return inner_query(root,0,n,l,r);} S all_query()const{return root?root->val:e();} void reset(long long l,long long r){inner_reset(root,0,n,l,r);} private: struct node; using ptr=unique_ptr; struct node{ S val; ptr l,r; node(const S&val):val(val),l(nullptr),r(nullptr){} }; ptr root; const long long n; void inner_set(ptr&nd,long long l,long long r,long long p,const S&x){ if(!nd)nd=make_unique(e()); if(r-l==1){nd->val=x;return;} long long m=(l+r)>>1; if(pl,l,m,p,x); else inner_set(nd->r,m,r,p,x); nd->val=op(nd->l?nd->l->val:e(),nd->r?nd->r->val:e()); } S inner_get(const ptr&nd,long long l,long long r,long long p)const{ if(!nd)return e(); if(r-l==1)return nd->val; long long m=(l+r)>>1; if(pl,l,m,p); return inner_get(nd->r,m,r,p); } S inner_query(const ptr&nd,long long nl,long long nr,long long l,long long r)const{ if(!nd||nr<=l||r<=nl)return e(); if(l<=nl&&nr<=r)return nd->val; long long m=(nl+nr)>>1; return op(inner_query(nd->l,nl,m,l,r),inner_query(nd->r,m,nr,l,r)); } void inner_reset(ptr&nd,long long nl,long long nr,long long l,long long r){ if(!nd||nr<=l||r<=nl)return; if(l<=nl&&nr<=r){ nd.reset();return; } long long m=(l+r)>>1; inner_reset(nd->l,nl,m,l,r); inner_reset(nd->r,m,nr,l,r); nd->val=op(nd->l?nd->l->val:e(),nd->r?nd->r->val:e()); } }; ll op(ll a,ll b){return a+b;} ll e(){return 0LL;} int main(){ dynamic_segtreeseg(1000000001); LL(n); ll ans=0; while(n--){ LL(t); if(t==0){ LL(x,y); //debug(t,x,y); ll now=seg[x]+y; //debug(now); seg.set(x,now); } else{ LL(l,r); //debug(t,l,r); ll now=seg.query(l,r+1); //debug(now,l,r); ans+=now; } } print(ans); }