#include #include #include using namespace std; #include #include template struct dualsegtree{ using F=function; const F lazycalcfn,updatefn; int n; T lazydefvalue; vectordat,lazy; vectorlazyflag; dualsegtree(int n_=0,T defvalue=0, const F lazycalcfn_=[](T a,T b){return a+b;}, const F updatefn_=[](T a,T b){return a+b;}, T lazydefvalue_=0 ):lazydefvalue(lazydefvalue_), lazycalcfn(lazycalcfn_),updatefn(updatefn_) { n=1; while(n&v) { for(int i=0;i0) { i=(i-1)/2; if(lazyflag[i])ret=updatefn(ret,lazy[i]); } return ret; } }; int N; main() { cin>>N; dualsegtreeP(N,0,[](int a,int b){return b;},[](int a,int b){return b;}); vector >A(N); for(int i=0;i>A[i].first; A[i].second=i; } sort(A.begin(),A.end()); for(int i=0;i