题解:P11930 [PA 2025] 吃树叶 / Liście
shinzAnmono · · 题解
绝顶搞笑题。
25s,
题面写了一大堆没用的,但是总结起来就是在
考虑块长为
#include<iostream>
#include<algorithm>
using ll=long long;
const int sz=1e6+10;
const int sqsz=1010;
namespace IO{
using ll=long long;
const int MAXSIZE=1<<21;
char buf[MAXSIZE],*pb,*pe;
#define gc() (pb==pe&&(pe=(pb=buf)+fread(buf,1,MAXSIZE,stdin),pb==pe)?EOF:*pb++)
inline ll read(){
ll x=0,f=1;
char c=gc();
while(!isdigit(c)){
if(c=='-')f=-1;
c=gc();
}
while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=gc();
return x*f;
}
char pbuf[MAXSIZE],*pp=pbuf;
int sta[35];
inline void push(const char &c) {
if(pp-pbuf==MAXSIZE)fwrite(pbuf,1,MAXSIZE,stdout),pp=pbuf;
*pp++=c;
}
inline void write(ll x){
if(x<0)push('-'),x=-x;
int top=0;
do sta[top++]=x%10,x/=10;while(x!=0);
while(top!=0)push(sta[--top]+'0');
}
inline std::string readline(){
std::string s;
char c;
while((c=gc())!='\n'&&c!=EOF)s+=c;
return s;
}
inline void write(std::string s){for(char &c:s)push(c);}
inline void flush(){if(pp-pbuf!=0)fwrite(pbuf,1,pp-pbuf,stdout),pp=pbuf;}
}
using IO::read,IO::write,IO::flush;
int belong[sz],bl[sz],br[sz],l[sz],a[sz];
ll tag[sz],suf[sz],v[sz];
short pos[sqsz][sz];
inline void add(int x,ll val){
for(int i=1;i<belong[x]+(x==br[belong[x]]);i++)tag[i]+=val;
if(x==br[belong[x]])return;
for(int i=bl[belong[x]];i<=x;i++)v[i]+=val;
suf[br[belong[x]]]=v[a[br[belong[x]]]];
for(int i=br[belong[x]]-1;i>=bl[belong[x]];i--)suf[i]=suf[i+1]+v[a[i]];
}
inline ll query(int x,int d){
ll res=0;
for(int i=1;i<belong[x]+(x==br[belong[x]]);i++)
if(pos[i][d]!=0)res+=suf[pos[i][d]+bl[i]-1]+tag[i]*(br[i]-pos[i][d]-bl[i]+2);
if(x!=br[belong[x]])for(int i=bl[belong[x]];i<=x;i++)if(l[i]>=d)res+=v[i]+tag[belong[x]];
return res;
}
int main(){
int n=read(),q=read()+read();
for(int i=1;i<=n;i++)l[i]=read();
int lim=2000,num=n/lim;
for(int i=1;i<=num;i++)bl[i]=br[i-1]+1,br[i]=i*lim;
if(br[num]!=n)num++,bl[num]=br[num-1]+1,br[num]=n;
for(int i=1;i<=num;i++){
for(int j=bl[i];j<=br[i];j++)belong[j]=i,a[j]=j;
std::sort(a+bl[i],a+br[i]+1,[&](int x,int y){return l[x]<l[y];});
int lst=1;
for(int j=bl[i];j<=br[i];j++)while(lst<=l[a[j]])pos[i][lst++]=j-bl[i]+1;
}
while(q--){
int op=read(),x=read(),y=read();
if(op==1)add(x,y);
else write(query(x,y)),write("\n");
}
flush();
return 0;
}