#include <iostream> #include <cstring> #include <unordered_map> #include <vector> #include <algorithm> using namespace std ; const int N =1e6; #define k1 k<<1 #define k2 k<<1|1 #define int long long int a[N], mx[N<<2], p[N<<2],n ; void up(int k){ if(mx[k1] >mx[k2]) mx[k] =mx[k1] , p[k] =p[k1] ; else mx[k] =mx[k2] ,p[k] =p[k2] ; } void build(int k,int l,int r){ if(l==r){ mx[k] =a[l] ; p[k] =l ; return ; } int md =(l+r)/2; build(k1,l,md) ,build(k2,md+1,r) ; up(k) ; } void cg(int k,int l,int r,int x,int v){ if(l==r){ mx[k] = v; p[k] =l; return ; } int md =(l+r)/2 ; if(x<=md) cg(k1,l,md,x,v); else cg(k2,md+1,r,x,v) ; up(k) ; } int pos ; int qq(int k,int l,int r,int x,int y){ if(x<=l and y>=r){ pos =p[k] ; return mx[k] ; } int md =(l+r)/2,t=0; if(x<=md){ t =max(t,qq(k1,l,md,x,y)); } if(y>md){ t=max(t,qq(k2,md+1,r,x,y)) ; } return t; }
标签:md,int,最大值,位置,k2,k1,区间,include,mx From: https://www.cnblogs.com/towboa/p/18049261