From 4b89030831baeb2fa8ce097a25f10d1c99f7d410 Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sun, 1 May 2016 15:35:41 +0800 Subject: [PATCH] From https://vijos.org/p/1081/solution --- QUSTOJ/1034_TenderRun.cpp | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 QUSTOJ/1034_TenderRun.cpp 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