"Luogu" p2617dynamic Ranking (tree array set Chairman tree)

Source: Internet
Author: User

Topic links

Tree array Set the Chairman tree is a little difficult to understand QWQ

Tree array set the visual comprehension of the Chairman tree should be: Each node of a tree array is a tree of chairmen.

Normal interval modification We are creating a tree of 1 line segments, tree arrays, and we'll create a log segment tree when we set up the Chairman tree.

General interval Query We are the from-1 and to two segments of the tree, the tree array sets the chairman of the tree when we put the from-1 prefix and the log segment tree and to the log segment tree is bad.

Comparative Metaphysics Qwq I don't seem to understand it now.

Put the code on it.

  

#include <cctype>#include<cstring>#include<cstdlib>#include<algorithm>#include<cstdio>#defineMid ((l+r) >>1)#defineMAXN 10005using namespaceStd;inlineLong LongRead () {Long Longnum=0, f=1; CharCh=GetChar ();  while(!isdigit (CH)) {        if(ch=='-') f=-1; CH=GetChar (); }     while(IsDigit (CH)) {num=num*Ten+ch-'0'; CH=GetChar (); }    returnnum*F;} InlineintLowinti) {returni& (-i); }ints[maxn*2],q[maxn*2];intrt[maxn* -* -];intsum[maxn* -* -];intls[maxn* -* -];intrs[maxn* -* -];intD[MAXN],W[MAXN],TOT,N,M,SIZE,POINT,TOTD,TOTW;voidBuildint&o,intLintR) {o=++tot; if(L==R)return;    Build (Ls[o],l,mid); Build (Rs[o],mid+1, R);}voidUpdateint&o,intLintRintLastintPintval) {o=++tot;    Ls[o]=ls[last];    Rs[o]=rs[last]; sum[o]=sum[last]+Val; if(L==R)return; if(p<=mid) Update (LS[O],L,MID,LS[LAST],P,VAL); ElseUpdate (rs[o],mid+1, R,rs[last],p,val);}voidAddint  from,intval) {    intvalue=q[ from];  while( from<=N) {Update (rt[ from],1, size,rt[ from],value,val);  from+=low ( from); }}intQueryintLintRinte) {    if(L==R)returnl; intCnt=0;  for(intI=1; i<=totw;++i) cnt+=Sum[ls[w[i]];  for(intI=1; i<=totd;++i) cnt-=Sum[ls[d[i]]; if(e<=CNT) {         for(intI=1; i<=totd;++i) d[i]=Ls[d[i]];  for(intI=1; i<=totw;++i) w[i]=Ls[w[i]]; returnquery (l,mid,e); }    Else{         for(intI=1; i<=totd;++i) d[i]=Rs[d[i]];  for(intI=1; i<=totw;++i) w[i]=Rs[w[i]]; returnQuery (mid+1, r,e-CNT); }}structque{BOOLF; int  from, To,rank; voidAddintOptintXintYintz) {f=opt; from=x;to=y;rank=Z; }}QUE[MAXN];intMain () {n=read (), m=read ();  for(intI=1; i<=n;++i) s[++point]=q[i]=read ();  for(intI=1; i<=m;++i) {        Charch[Ten];intx, y; scanf ("%s%d%d",ch,&x,&y); if(ch[0]=='Q'){            intz=read (); Que[i].add (0, x, Y, z); }        Else{Que[i].add (1, X, Y,0); s[++point]=y; }} sort (S+1, s+point+1); Size=unique (s+1, s+point+1)-s-1;  for(intI=1; i<=n;++i) Q[i]=lower_bound (s+1, s+size+1, Q[i])-s;  for(intI=1; i<=m;++i)if(QUE[I].F) Que[i].to=lower_bound (s+1, s+size+1, que[i].to)-s; //build (rt[0],1,size);     for(intI=1; i<=n;++i) Add (i,1);  for(intI=1; i<=m;++i) {        BOOLF=QUE[I].F;int  from=que[i]. from, to=que[i].to,rank=Que[i].rank; if(f) {Add ( from,-1); q[ from]=to; Add from,1); }        Else{TOTD=totw=0;  for(intj= from-1; J;j-=low (j)) d[++totd]=Rt[j];  for(intJ=to;j;j-=low (j)) w[++totw]=Rt[j]; printf ("%d\n", S[query (1, Size,rank)]); }    }    return 0;}

"Luogu" p2617dynamic Ranking (tree array set Chairman tree)

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.