"Tree array set weight segment tree" bzoj1901 Zju2112 Dynamic Rankings

Source: Internet
Author: User

Who cares if this thing is called a tree array set chairman tree Who am I anxious?

is clearly the tree array of each node maintains a dynamic open node of the weight segment tree just

Well, there's actually only one pointer, the current node of the weight segment tree that points to the node

To have the pointer point to the root node before each query

There is no correlation between the weights of different nodes and the segment tree.

Can see this: Http://blog.csdn.net/popoqqq/article/details/40108669?utm_source=tuicool

#include <cstdio> #include <algorithm>using namespace std;struct data{int p,v;} T[20010];int E,en=1;bool CMP (const data &AMP;A,CONST data &b) {return A.V&LT;B.V;} int N,m,a[20010],ma[20010],x[10010],y[10010],z[10010];char op[10010][2];struct node{int v,ch[2];} T[20010*195];int root[10010],now[2][10010];void init_root (int ql,int qr) {--ql;for (; ql;ql-= (ql& (-QL))) NOW[0][QL ]=root[ql];for (; qr;qr-= (qr& (-QR))) NOW[1][QR]=ROOT[QR];} int qbit (int k,int ql,int qr) {int res=0;for (int x=ql-1;x;x-= (x))) x& (int res-=t[t[now[0][x]].ch[0]].v;for; x-= (x& (x))) Res+=t[t[now[1][x]].ch[0]].v;bool f= (res<k); for (int x=ql-1;x;x-= (x& (x))) now[0][x]=t[now[ 0][x]].ch[f];for (; qr;qr-= (qr& (-QR))) Now[1][qr]=t[now[1][qr]].ch[f];return Res;}    int Kth (int k,int ql,int qr,int l,int r)//k decimal value {if (l==r) return l;    int m= (l+r>>1), TMP;    if ((Tmp=qbit (K,QL,QR)) >=k) return Kth (K,QL,QR,L,M); Return Kth (K-TMP,QL,QR,M+1,R);} void Update (int p,int v,int cur,int l,int R) {if (l==R) {t[cur].v+=v;  Return }int m= (l+r>>1); if (p<=m) {if (!  T[cur].ch[0]) t[cur].ch[0]=++e;  Update (P,V,T[CUR].CH[0],L,M); }else {if (!  T[CUR].CH[1]) t[cur].ch[1]=++e;  Update (P,V,T[CUR].CH[1],M+1,R); }T[CUR].V=T[T[CUR].CH[0]].V+T[T[CUR].CH[1]].V;} void update (int pp,int P,int v) {for (;pp <=n;pp+= (pp& (-PP))) update (p,v,root[pp],1,en);} int main () {//freopen ("bzoj1901.in", "R", stdin),//freopen ("Bzoj1901.out", "w", stdout), scanf ("%d%d", &n,&m);  for (int i=1;i<=n;++i) scanf ("%d", &AMP;T[I].V), e=n;for (int i=1;i<=m;++i) {scanf ("%s%d", Op[i],&x[i]);  if (op[i][0]== ' C ') scanf ("%d", &AMP;T[++E].V);  else scanf ("%d%d", &y[i],&z[i]); }for (int i=1;i<=e;++i) t[i].p=i;sort (t+1,t+e+1,cmp); ma[a[t[1].p]=1]=t[1].v;for (int i=2;i<=e;++i) {if (t[i].v!  =T[I-1].V) ++en;  MA[A[T[I].P]=EN]=T[I].V; }e=n;for (int i=1;i<=m;++i) if (op[i][0]== ' C ') z[i]=a[++e];e=n;for (int i=1;i<=n;++i) root[i]=i;for (int i=1;i< =n;++i) Update (i,a[i],1); for (int i=1;i<=m;++i) if (op[i][0]== ' C ') {Update (x[i],a[x[i]],-1);      A[x[i]]=z[i];    Update (x[i],z[i],1);      } else {init_root (x[i],y[i]);    printf ("%d\n", Ma[kth (Z[i],x[i],y[i],1,en)]); }return 0;}

Tree Array Set weight segment tree bzoj1901 Zju2112 Dynamic rankings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.