Cf558e-a Simple Task Segment tree

Source: Internet
Author: User

Give a lowercase letter string, and then Q operation, A,b,c, C is 0, the interval [a, b] by the inverse dictionary sequence, C is 1, this interval is sorted by dictionary order. Using a line segment tree to maintain the number of each letter of each node, after each operation, the violence will be composed of the letter a interval, the letter B, and so on, all elements of the interval is updated to a, B, and so on. Make a lazy mark, and the interval update will be done.

#pragmaComment (linker, "/stack:102400000,102400000")#define_crt_secure_no_warnings#include<stdio.h>#include<iostream>#include<string>#include<queue>#include<stack>#include<list>#include<stdlib.h>#include<algorithm>#include<vector>#include<map>#include<cstring>#include<Set>using namespaceStd;typedefLong LongLL;Const intMoD =1000000007;#defineLson l,mid,rt<<1#defineRson mid+1,r,rt<<1|1Const intMAXN = 1e5 + -;intch[maxn<<2][ -];intCOLOR[MAXN <<2];CharSTR[MAXN];voidUpintRT) {     for(inti =0; I < -; i++) {Ch[rt][i]= Ch[rt <<1][i] + ch[rt <<1|1][i]; }}voidDownintLintRintRT) {    if(Color[rt] = =-1)return; intMid = (L + r) >>1;  for(inti =0; I < -; i++) Ch[rt <<1][i] =0, Ch[rt <<1|1][i] =0; Ch[rt<<1][COLOR[RT]] = (mid-l +1); Ch[rt <<1|1][COLOR[RT]] = R-mid; Color[rt<<1] = Color[rt <<1|1] =Color[rt]; COLOR[RT]= -1;}voidBuildintLintRintRT) {Color[rt]= -1; if(L = =r) {intt = str[l]-'a'; Ch[rt][t]++; return; }    intMid = (L + r) >>1;    Build (Lson);    Build (Rson); Up (RT);}intAskintLintRintAddintLintRintRT) {    if(L <= L&&r <=R) {returnCh[rt][add]; }    intMid = (L + r) >>1; intAns =0;    Down (l, R, RT); if(L <= mid) ans + =Ask (L, R, add, Lson); if(R > mid) ans + =Ask (L, R, add, Rson); returnans;}voidUpdateintLintRintAddintLintRintRT) {    if(L <= L&&r <=R) { for(inti =0; I < -; i++) Ch[rt][i] =0; Ch[rt][add]= (R-l +1); COLOR[RT]=add; return;    } down (l, R, RT); intMid = (L + r) >>1; if(L <=mid) Update (L, R, add, Lson); if(R >mid) Update (L, R, add, Rson); Up (RT);}intAns =0;voidShowintLintRintRT) {    if(L = =r) { for(inti =0; I < -; i++)if(Ch[rt][i]) printf ("%c", i +'a'); return;    } down (L,R,RT); intMid = (L + r) >>1; Show (Lson); Show (Rson);}intcc[ -];intMain () {//freopen ("1.in", "R", stdin); //freopen ("2.in", "w", stdout);    intq, N; intA, B, C; CIN>> N >>Q; scanf ("%s", str); Build (0, N-1,1);  while(q--) {scanf ("%d%d%d", &a, &b, &c); A--; b--; if(c = =1) {             for(inti =0; I < -; i++) Cc[i +1] = Ask (A, B, I,0N1,1); intLL =A;  for(inti =0; I < -; i++) {                if(Cc[i +1] ==0)Continue; Update (LL, LL+ Cc[i +1] -1I0N1,1); ll= ll + cc[i +1]; }        }        Else {             for(inti =0; I < -; i++) Cc[i +1] = Ask (A, B, I,0N1,1); intLL =A;  for(inti = -; I >=0; i--) {                if(Cc[i +1] ==0)Continue; Update (LL, LL+ Cc[i +1] -1I0N1,1); ll= ll + cc[i +1]; }}} Show (0N1,1); return 0;}

Cf558e-a Simple Task Segment 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.