- BC20260050's blog
111
- 2025-3-25 9:16:35 @
#include<bits/stdc++.h> using namespace std; #define int long long const int INF=-2e18,N=1e6+10; int n,m,a[N],val[N4],tag[N4],tag2[N4],siz[N4],b[N]; void build(int l,int r,int num){ if(l==r){ val[num]=a[l]; tag2[num]=INF; return ; } int mid=(l+r)>>1; build(l,mid,num2); build(mid+1,r,num2+1); val[num]=max(val[num2+1],val[num2]); }
void pushdown2(int x){ if(tag2[x]!=INF){ tag[2x]=0; tag[2x+1]=0; tag2[2x+1]=tag2[x]; tag2[2x]=tag2[x]; val[2x]=tag2[x]; val[2x+1]=tag2[x]; tag2[x]=INF; } } void pushdown(int x){ if(tag[x]){ pushdown2(x); tag[2x+1]+=tag[x]; tag[2x]+=tag[x]; val[2x]+=tag[x]; val[2x+1]+=tag[x]; tag[x]=0; } } void qwq(int l,int r,int x,int y,int num,int k){ if(l>=x&&r<=y){ pushdown2(num); val[num]+=k; tag[num]+=k; return ; } pushdown2(num); pushdown(num); int mid=(l+r)>>1; if(x<=mid)qwq(l,mid,x,y,num2,k); if(mid<y)qwq(mid+1,r,x,y,num2+1,k); val[num]=max(val[num2+1],val[num2]); } void qwq2(int l,int r,int x,int y,int num,int k){ if(l>=x&&r<=y){ tag[num]=0; val[num]=k; tag2[num]=k; return ; } pushdown2(num); pushdown(num); int mid=(l+r)>>1; if(x<=mid)qwq2(l,mid,x,y,num2,k); if(mid<y)qwq2(mid+1,r,x,y,num2+1,k); val[num]=max(val[num2+1],val[num2]); } int qvq(int l,int r,int x,int y,int num){ if(l>=x&&r<=y){ return val[num]; } pushdown2(num); pushdown(num); int mid=(r+l)>>1,ans=INF; if(x<=mid)ans=max(qvq(l,mid,x,y,num2),ans); if(mid<y)ans=max(ans,qvq(mid+1,r,x,y,num2+1)); return ans; } signed main(){ scanf("%lld",&n); for(int i=1;i<=n;i++){ scanf("%lld",&a[i]); b[i]=a[i]; } sort(b+1,b+n+1); for(int i=1;i<=n;i++){ a[i]=lower_bound(b+1,b+n+1,a[i])-b; } return 0; }