Cf558e-a Simple task-Segment tree + count sort

Source: Internet
Author: User

The principle of counting sorting, as long as you know there are a few number than I small, you can know the position of I

This problem has only 26 letters, 26 line segment tree, and then update the interval

1#include <cstdio>2#include <cstring>3#include <algorithm>4 5 //using namespace std;6 Const intMAXN = 1e5+Ten;7 8 intn,q;9 CharLINE[MAXN];Ten  One #defineLson Rt<<1,l,mid A #defineRson Rt<<1|1,mid+1,r - #defineRoot 1,1,n -  the structsegrtree{ -     intnum[maxn<<2]; -     intlazy[maxn<<2]; -     voidInit () +     { -memset (lazy,-1,sizeoflazy); +     } A     voidPUSH_UP (intRT) at     { -NUM[RT] = num[rt<<1] + num[rt<<1|1]; -     } -     voidPush_down (intRtintm) -     { -         if(LAZY[RT]! =-1) in         { -num[rt<<1] = (M (m>>1))*Lazy[rt]; tonum[rt<<1|1] = (m>>1)*Lazy[rt]; +lazy[rt<<1] = lazy[rt<<1|1] =Lazy[rt]; -LAZY[RT] =-1; the         } *     } $     voidBuildintKindintRtintLintR)Panax Notoginseng     { -         if(L = =R) the         { +NUM[RT] = line[l-1]==kind+'a'; A             //if (line[l-1]== ' C ') printf ("%c pos:%d \ n", kind+ ' a ', l); the             return ; +         } -         intMid = (l+r) >>1; $ build (Kind,lson); $ build (Kind,rson); - push_up (RT); -     } the     voidUpdateintLintRintDintRtintLintR) -     {Wuyi         if(l <= l && R >=R) the         { -NUM[RT] = (r-l+1)*D; WuLAZY[RT] =D; -             return ; About         } $Push_down (rt,r-l+1); -         intMid = (l+r) >>1; -         if(L <=mid) Update (L,r,d,lson); -         if(R >mid) Update (L,r,d,rson); A push_up (RT); +     } the     intQueryintLintRintRtintLintR) -     { $         if(l <= l && R >=R) the         { the             returnNum[rt]; the         } thePush_down (rt,r-l+1); -         intMid = (l+r) >>1; in         intres =0; the  the         if(R <= mid) res =query (L,r,lson); About         Else if(L > Mid) res =query (L,r,rson); the         Elseres = query (L,r,lson) +query (L,r,rson); the  the push_up (RT); +         returnRes; -     } the}alpha[ -];Bayi  the voidSortintLintRintk) the { -     intpos,cnt; -     if(k = =1) the     { thepos =l; the          for(intI=0;i< -; i++) the         { -CNT =alpha[i].query (l,r,root); the             //printf ("[%d,%d]%c k:%d pos:%d cnt:%d\n", l,r,i+ ' a ', k,pos,cnt); the             if(CNT) the             {94Alpha[i].update (L,r,0, root); theAlpha[i].update (pos,pos+cnt-1,1, root); thepos + =CNT; the             }98         } About     } -     Else101     {102pos =l;103          for(intI= -; i>=0; i--)104         { theCNT =alpha[i].query (l,r,root);106             //printf ("[%d,%d]%c k:%d pos:%d cnt:%d\n", l,r,i+ ' a ', k,pos,cnt);107             if(CNT)108             {109Alpha[i].update (L,r,0, root); theAlpha[i].update (pos,pos+cnt-1,1, root);111pos + =CNT; the             }113         } the     } the } the 117 intMain ()118 {119     //freopen ("Input.txt", "R", stdin); - 121scanf"%d%d",&n,&Q);122scanf"%s", line);123 124      for(intI=0;i< -; i++) the     {126 alpha[i].init ();127 Alpha[i].build (i,root); -         //printf ("Tot num:%c%d\n", i+ ' a ', Alpha[i].query (1,n,root));129     } the     //printf ("c:%d c:%d\n", Alpha[2].query (1,n,root), Alpha[2].query (7,10,root));131      for(intI=0, l,r,k;i<q;i++) the     {133scanf"%d%d%d",&l,&r,&k);134 sort (l,r,k);135     }136      for(intI=1; i<=n;i++)137     {138          for(intj=0;j< -; j + +)if(Alpha[j].query (i,i,root))139         { $printf"%c",'a'+j);141         }142     }143Puts"");144}

Cf558e-a Simple task-Segment tree + count sort

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.