#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
const int M=1e6;
const int B=1000;
int a[1001000];
int tp[2002000],p[2002000],w[2002000];
int n,m,z;
int nxt[1001000];
ull ans[2002000];
ull tag,sum[1001000],tag2[B+5],tmp[B+5];
int cnt[B+5];
int ind[1001000];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>z;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=m+z;i++)
cin>>tp[i]>>p[i]>>w[i];
for(int i=0;i<=n/B;i++)
{
int L=max(1,i*B);
int R=min(n,i*B+B-1);
vector<int> pool;
for(int j=L;j<=R;j++)
pool.push_back(a[j]);
sort(pool.begin(),pool.end());
pool.resize(unique(pool.begin(),pool.end())-pool.begin());
for(int j=L;j<=R;j++)
ind[j]=upper_bound(pool.begin(),pool.end(),a[j])-pool.begin();
memset(nxt,0,sizeof(nxt));
memset(cnt,0,sizeof(cnt));
int s=pool.size();
for(int i=0;i<s;i++)
nxt[pool[i]]=i+1;
for(int j=L;j<=R;j++)
cnt[ind[j]]++;
for(int i=s;i>=1;i--)
cnt[i]+=cnt[i+1];
for(int i=M;i>=1;i--)
if(!nxt[i])
{
nxt[i]=nxt[i+1];
if(!nxt[i]) nxt[i]=s+1;
}
tag=0;
memset(tag2,0,sizeof(tag2));
for(int j=1;j<=m+z;j++)
if(p[j]>=L)
{
if(tp[j]==1)
{
if(p[j]>=R)
tag+=w[j];
else
{
memset(tmp,0,sizeof(tmp));
for(int po=L;po<=p[j];po++)
{
sum[po]+=w[j];
tmp[ind[po]]+=w[j];
}
for(int v=s;v>=1;v--)
{
tmp[v]+=tmp[v+1];
tag2[v]+=tmp[v];
}
}
}
else
{
if(p[j]>=R)
{
ans[j]+=tag*cnt[nxt[w[j]]];
ans[j]+=tag2[nxt[w[j]]];
}
else
{
for(int po=L;po<=p[j];po++)
if(a[po]>=w[j])
ans[j]+=tag+sum[po];
}
}
}
}
for(int i=1;i<=m+z;i++)
if(tp[i]==2)
cout<<ans[i]<<'\n';
return 0;
}
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 | #include<bits/stdc++.h> using namespace std; using ull=unsigned long long; const int M=1e6; const int B=1000; int a[1001000]; int tp[2002000],p[2002000],w[2002000]; int n,m,z; int nxt[1001000]; ull ans[2002000]; ull tag,sum[1001000],tag2[B+5],tmp[B+5]; int cnt[B+5]; int ind[1001000]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m>>z; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=m+z;i++) cin>>tp[i]>>p[i]>>w[i]; for(int i=0;i<=n/B;i++) { int L=max(1,i*B); int R=min(n,i*B+B-1); vector<int> pool; for(int j=L;j<=R;j++) pool.push_back(a[j]); sort(pool.begin(),pool.end()); pool.resize(unique(pool.begin(),pool.end())-pool.begin()); for(int j=L;j<=R;j++) ind[j]=upper_bound(pool.begin(),pool.end(),a[j])-pool.begin(); memset(nxt,0,sizeof(nxt)); memset(cnt,0,sizeof(cnt)); int s=pool.size(); for(int i=0;i<s;i++) nxt[pool[i]]=i+1; for(int j=L;j<=R;j++) cnt[ind[j]]++; for(int i=s;i>=1;i--) cnt[i]+=cnt[i+1]; for(int i=M;i>=1;i--) if(!nxt[i]) { nxt[i]=nxt[i+1]; if(!nxt[i]) nxt[i]=s+1; } tag=0; memset(tag2,0,sizeof(tag2)); for(int j=1;j<=m+z;j++) if(p[j]>=L) { if(tp[j]==1) { if(p[j]>=R) tag+=w[j]; else { memset(tmp,0,sizeof(tmp)); for(int po=L;po<=p[j];po++) { sum[po]+=w[j]; tmp[ind[po]]+=w[j]; } for(int v=s;v>=1;v--) { tmp[v]+=tmp[v+1]; tag2[v]+=tmp[v]; } } } else { if(p[j]>=R) { ans[j]+=tag*cnt[nxt[w[j]]]; ans[j]+=tag2[nxt[w[j]]]; } else { for(int po=L;po<=p[j];po++) if(a[po]>=w[j]) ans[j]+=tag+sum[po]; } } } } for(int i=1;i<=m+z;i++) if(tp[i]==2) cout<<ans[i]<<'\n'; return 0; } |
English