diff --git a/QUSTOJ/1034_TenderRun.cpp b/QUSTOJ/1034_TenderRun.cpp new file mode 100644 index 0000000..c01ef72 --- /dev/null +++ b/QUSTOJ/1034_TenderRun.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include + +using namespace std; +const int maxn=100010; + +struct Q{ + int l,r,a,b,sum; +}tr[maxn*20]; + +int fir[maxn],cnt; +int n,k,Sot[maxn],h[maxn],pos; + +void Build(int a,int b,int &rt) +{ + int md=(a+b)>>1; + rt=++cnt; + tr[rt].a=a; + tr[rt].b=b; + if(a==b)return; + Build(a,md,tr[rt].l); + Build(md+1,b,tr[rt].r); +} + +void Add(int pre,int &rt,int a,int b) +{ + rt=++cnt; + tr[rt].l=tr[pre].l; + tr[rt].r=tr[pre].r; + tr[rt].a=tr[pre].a; + tr[rt].b=tr[pre].b; + + tr[rt].sum=tr[pre].sum+1; + + if(a>1; + + if(pos<=md)Add(tr[pre].l,tr[rt].l,a,md); + else Add(tr[pre].r,tr[rt].r,md+1,b); + } +} +#define Cmp(x) tr[tr[x].l].sum +int Query(int pre,int rt,int a,int b,int K) +{ + if(a==b) return Sot[a]; + + int md=(a+b)>>1; + + int D=Cmp(rt)-Cmp(pre); + if(D