Bzoj 1901 dynamic rankings chair tree

Source: Internet
Author: User

The modifiable range is k-small.

This chairman left me behind for two days... After the count on a tree is cut off, I always think that the Chairman tree with modification is a tree number set of persistent line segments... In fact, I was misled...

The relationships between the chairman tree with Nima band and the tree with persistent line segments are all wooden !!!

That is, the dynamic weight line segment tree !!!


Okay, here is a brief introduction to the Chairman tree:

1. The outer tree Array

2. Line Segment tree

3. The line segment tree dynamically opens nodes. That's all. It has nothing to do with durability.

4. The line segment tree at one point has no relationship with other vertices.

5. normally insert the tree into the tree according to the common tree.

7. Answer questions in two minutes

8. The number of nodes is nlog ^ 2N

9. Focus on the problem. No. What do you see on the sixth point.


#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define M 10100using namespace std;struct Tree{    Tree *ls,*rs;    int num;}*tree[M],mempool[2002002],*C=mempool;int n,m,a[M];void Insert(Tree*&p,int x,int y,int val){    int mid=x+y>>1;    if(!p) p=C++;    p->num++;    if(x==y)        return ;    if(val<=mid)        Insert(p->ls,x,mid,val);    else        Insert(p->rs,mid+1,y,val);}void Delete(Tree*&p,int x,int y,int val){    int mid=x+y>>1;    p->num--;    if(x==y)        return ;    if(val<=mid)        Delete(p->ls,x,mid,val);    else        Delete(p->rs,mid+1,y,val);}int Get_Ans(Tree*p,int x,int y,int val){    int mid=x+y>>1;    if(!p)        return 0;    if(!p->num)        return 0;    if(x==y)        return p->num;    if(val<=mid)        return Get_Ans(p->ls,x,mid,val);    else        return (p->ls?p->ls->num:0) + Get_Ans(p->rs,mid+1,y,val);}void Update(int x,int y){    for(;x<=n;x+=x&-x)        Insert(tree[x],0,1000000000,y);}void Downdate(int x,int y){    for(;x<=n;x+=x&-x)        Delete(tree[x],0,1000000000,y);}int Get_Ans(int x,int y){    int re=0;    for(;x;x-=x&-x)        re+=Get_Ans(tree[x],0,1000000000,y);    return re;}int Bisection(int x,int y,int k){    int l=0,r=1000000000;    while(l+1<r)    {        int mid=l+r>>1;        if( Get_Ans(y,mid) - Get_Ans(x-1,mid) >= k )            r=mid;        else            l=mid;    }    if( Get_Ans(y,l) - Get_Ans(x-1,l) >= k )        return l;    return r;}int main(){    int i,x,y,k;    char p[10];    cin>>n>>m;    for(i=1;i<=n;i++)        scanf("%d",&a[i]),Update(i,a[i]);    for(i=1;i<=m;i++)    {        scanf("%s",p);        if(p[0]=='Q')            scanf("%d%d%d",&x,&y,&k),printf("%d\n", Bisection(x,y,k) );        else            scanf("%d%d",&x,&y),Downdate(x,a[x]),a[x]=y,Update(x,a[x]);    }}


Bzoj 1901 dynamic rankings chair 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.