#pragma GCC optimize("Ofast") #pragma GCC optimize("O2") #include<bits/stdc++.h> bool Mbg; using namespace std; /*--------------------------------------------------------------------------------------*/ #define cin cio #define cout cio #define Fs 100000 #define inline __inline__ __attribute__((always_inline)) #define iopt inline IO& operator #define Tc()(_A==_B&&(_B=(_A=Fi)+fread(Fi,1,100000,stdin),_A==_B)?EOF:*_A++) #define Pc(Ch)(FS<Fs?Fo[FS++]=Ch:(fwrite(Fo,1,Fs,stdout),Fo[(FS=0)++]=Ch)) int Tp,FS;char Ch,*_A,*_B,Fi[Fs],Fo[Fs],Sk[Fs]; struct IO{ template<typename T> iopt>>(T&x){x=0;while(!isdigit(Ch=Tc()));while(x=10*x +(Ch&15),isdigit(Ch=Tc()));return*this;} iopt>>(char*x){int I=0;for(;((x[I]=Tc())!=' ')&&(x[I]!='\n');++I);x[I]='\0';return*this;} iopt>>(char&x){x=Tc();return*this;} template<typename T> iopt<<(T x){if(!x){return Pc('0'),*this;}if(x<0)Pc('-'),x=-x;while(x)Sk[++Tp]=x%10+48,x/=10;while(Tp)Pc(Sk[Tp--]);return*this;} iopt<<(const char*x){for(;*x!='\0';Pc(*(x++)));return*this;} iopt<<(char x){Pc(x);return*this;};~IO(){fwrite(Fo,1,FS,stdout),FS=0;}void tie(int){} }cio;/*----------------------------------------------------------------------------------*/ #define vec vector #define pb push_back #define eb emplace_back #define siz(vec) (int)((vec).size()) #define all(vec) (vec).begin(),(vec).end() template<class T> void operator +=(vec<T> &lhs,const T &rhs){lhs.push_back(rhs);} #define pii pair<int,int> #define x first #define y second #define mp make_pair #define exc(expr) if(expr)continue; #define stop(expr) if(expr)break; #define ret(expr) if(expr)return; #define deb(var) cerr<<#var<<'='<<(var)<<"; " #define debl(var) cerr<<#var<<'='<<(var)<<";\n" #define ins insert #define era erase #define lb lower_bound #define ub upper_bound #define int long long #define inf (long long)(1e18) template<class T> bool Min(T &x,const T &y){return x>y?x=y,1:0;} template<class T> bool Max(T &x,const T &y){return x<y?x=y,1:0;} const int mod=998244353; void Add(int &x,const int &y){x=x+y<mod?x+y:x+y-mod;} void Dec(int &x,const int &y){x=x>=y?x-y:x-y+mod;} int fpm(int x,int y){ int ans=1;for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)ans=1ll*x*ans%mod;return ans; } int n,q1,q2,a[1000010],b[1000010]; const int N=1e6; int B; // const int N=1000,B=sqrt(N); int bel[N+5]; int tot,L[N+5],R[N+5]; int fir[N+5]; int sum[N+5]; int ord[N+5]; int tag[N+5]; void rebuild(int x){ sum[L[x]]=b[ord[L[x]]]; for(int i=L[x]+1;i<=R[x];i++){ sum[i]=sum[i-1]+b[ord[i]]; } } void work(){ cin>>n>>q1>>q2; if(q1+q2==0){ return; } B=max(1ll,min((int)sqrtl((q2*17+q1)*n/(q1+q2)),n)); for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n;i++){ bel[i]=(i-1)/B+1; } tot=bel[n]; for(int i=1;i<=tot;i++){ L[i]=(i-1)*B+1; R[i]=i*B; } R[tot]=n; iota(ord+1,ord+n+1,1); for(int i=1;i<=tot;i++){ sort(ord+L[i],ord+R[i]+1,[&](auto x,auto y){ return a[x]>a[y]; }); for(int x=L[i];x<=R[i];x++){ fir[x]=a[ord[x]]; } rebuild(i); } for(int i=1,op,x,y;i<=q1+q2;i++){ cin>>op>>x>>y; if(op==1){ for(int i=1;i<bel[x];i++){ tag[i]+=y; } for(int i=L[bel[x]];i<=x;i++){ b[i]+=y; } rebuild(bel[x]); }else{ int ans=0; for(int i=1;i<bel[x];i++){ int x=ub(fir+L[i],fir+R[i]+1,y,greater<int>())-fir-1; if(x>=L[i])ans+=sum[x]+tag[i]*(x-L[i]+1); } for(int i=L[bel[x]];i<=x;i++){ if(a[i]>=y) ans+=b[i]+tag[bel[x]]; } cout<<ans<<'\n'; } } } bool Med; signed main(){ ios::sync_with_stdio(0), cin.tie(0),cout.tie(0); int T=1;while(T--)work(); // cerr<<"Time: "<<clock()<<" ms;\n"; // cerr<<"Memory: "<<abs(&Med-&Mbg)/1024.0/1024.0<<" MiB.\n"; } /* - CONTINUE, NON-STOPPING, FOR THE FAITH - START TYPING IF YOU DON'T KNOW WHAT TO DO - STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | #pragma GCC optimize("Ofast") #pragma GCC optimize("O2") #include<bits/stdc++.h> bool Mbg; using namespace std; /*--------------------------------------------------------------------------------------*/ #define cin cio #define cout cio #define Fs 100000 #define inline __inline__ __attribute__((always_inline)) #define iopt inline IO& operator #define Tc()(_A==_B&&(_B=(_A=Fi)+fread(Fi,1,100000,stdin),_A==_B)?EOF:*_A++) #define Pc(Ch)(FS<Fs?Fo[FS++]=Ch:(fwrite(Fo,1,Fs,stdout),Fo[(FS=0)++]=Ch)) int Tp,FS;char Ch,*_A,*_B,Fi[Fs],Fo[Fs],Sk[Fs]; struct IO{ template<typename T> iopt>>(T&x){x=0;while(!isdigit(Ch=Tc()));while(x=10*x +(Ch&15),isdigit(Ch=Tc()));return*this;} iopt>>(char*x){int I=0;for(;((x[I]=Tc())!=' ')&&(x[I]!='\n');++I);x[I]='\0';return*this;} iopt>>(char&x){x=Tc();return*this;} template<typename T> iopt<<(T x){if(!x){return Pc('0'),*this;}if(x<0)Pc('-'),x=-x;while(x)Sk[++Tp]=x%10+48,x/=10;while(Tp)Pc(Sk[Tp--]);return*this;} iopt<<(const char*x){for(;*x!='\0';Pc(*(x++)));return*this;} iopt<<(char x){Pc(x);return*this;};~IO(){fwrite(Fo,1,FS,stdout),FS=0;}void tie(int){} }cio;/*----------------------------------------------------------------------------------*/ #define vec vector #define pb push_back #define eb emplace_back #define siz(vec) (int)((vec).size()) #define all(vec) (vec).begin(),(vec).end() template<class T> void operator +=(vec<T> &lhs,const T &rhs){lhs.push_back(rhs);} #define pii pair<int,int> #define x first #define y second #define mp make_pair #define exc(expr) if(expr)continue; #define stop(expr) if(expr)break; #define ret(expr) if(expr)return; #define deb(var) cerr<<#var<<'='<<(var)<<"; " #define debl(var) cerr<<#var<<'='<<(var)<<";\n" #define ins insert #define era erase #define lb lower_bound #define ub upper_bound #define int long long #define inf (long long)(1e18) template<class T> bool Min(T &x,const T &y){return x>y?x=y,1:0;} template<class T> bool Max(T &x,const T &y){return x<y?x=y,1:0;} const int mod=998244353; void Add(int &x,const int &y){x=x+y<mod?x+y:x+y-mod;} void Dec(int &x,const int &y){x=x>=y?x-y:x-y+mod;} int fpm(int x,int y){ int ans=1;for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)ans=1ll*x*ans%mod;return ans; } int n,q1,q2,a[1000010],b[1000010]; const int N=1e6; int B; // const int N=1000,B=sqrt(N); int bel[N+5]; int tot,L[N+5],R[N+5]; int fir[N+5]; int sum[N+5]; int ord[N+5]; int tag[N+5]; void rebuild(int x){ sum[L[x]]=b[ord[L[x]]]; for(int i=L[x]+1;i<=R[x];i++){ sum[i]=sum[i-1]+b[ord[i]]; } } void work(){ cin>>n>>q1>>q2; if(q1+q2==0){ return; } B=max(1ll,min((int)sqrtl((q2*17+q1)*n/(q1+q2)),n)); for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n;i++){ bel[i]=(i-1)/B+1; } tot=bel[n]; for(int i=1;i<=tot;i++){ L[i]=(i-1)*B+1; R[i]=i*B; } R[tot]=n; iota(ord+1,ord+n+1,1); for(int i=1;i<=tot;i++){ sort(ord+L[i],ord+R[i]+1,[&](auto x,auto y){ return a[x]>a[y]; }); for(int x=L[i];x<=R[i];x++){ fir[x]=a[ord[x]]; } rebuild(i); } for(int i=1,op,x,y;i<=q1+q2;i++){ cin>>op>>x>>y; if(op==1){ for(int i=1;i<bel[x];i++){ tag[i]+=y; } for(int i=L[bel[x]];i<=x;i++){ b[i]+=y; } rebuild(bel[x]); }else{ int ans=0; for(int i=1;i<bel[x];i++){ int x=ub(fir+L[i],fir+R[i]+1,y,greater<int>())-fir-1; if(x>=L[i])ans+=sum[x]+tag[i]*(x-L[i]+1); } for(int i=L[bel[x]];i<=x;i++){ if(a[i]>=y) ans+=b[i]+tag[bel[x]]; } cout<<ans<<'\n'; } } } bool Med; signed main(){ ios::sync_with_stdio(0), cin.tie(0),cout.tie(0); int T=1;while(T--)work(); // cerr<<"Time: "<<clock()<<" ms;\n"; // cerr<<"Memory: "<<abs(&Med-&Mbg)/1024.0/1024.0<<" MiB.\n"; } /* - CONTINUE, NON-STOPPING, FOR THE FAITH - START TYPING IF YOU DON'T KNOW WHAT TO DO - STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING */ |