Letters removing
Test instructions: give you a string of length n, then perform m delete operation, delete a character within the interval [l,r] Each time, delete the string and then forward it to the next, and then delete the string.
Exercises
1#include <Set>2#include <iostream>3#include <string>4 using namespacestd;5 #defineLson l,m,rt<<16 #defineRson m+1,r,rt<<1|17 Const intN = 2e5+Ten;8 intN, M;9 inttree[n<<2];Ten stringSTR, TMP; One Set<int> g[ the]; A voidPushup (intRT) - { -TREE[RT] = tree[rt<<1|1] + tree[rt<<1]; the } - voidRevise (intLintLintRintRT) - { - if(L = =R) + { -tree[rt]++; + return ; A } at intm = L+r >>1; - if(L <=m) revise (L,lson); - Elserevise (L,rson); - pushup (RT); - } - intQuery (intLintRintLintRintRT) in { - if(l <= l && R <=R) to returnTree[rt]; + intm = L+r >>1; - intRET =0; the if(L <=m) ret + =Query (L,r,lson); * if(M < R) ret+=Query (L,r,rson); $ returnret;Panax Notoginseng } - intMian () the { +Ios::sync_with_stdio (false); ACin.tie (0); theCout.tie (0); +CIN >> N >>m; -CIN >>str; $ Set<int>:: iterator it; $str ="#"+STR;//move string to right whole one - for(inti =1; I <= N; i++) -g[str[i]-'0'].insert (i);//Save the corresponding position to the corresponding set the intL, R; - while(m--)Wuyi { theCIN >> L >> R >>tmp; - BOOLFlag = (L==R);//determine if L = = R is established if set up can be less than once two minutes Wu if(L + tree[1] > N) L = n+1;//If the interval left endpoint is greater than the effective length - Else //then it means there's no need to delete the operation. About { $ intll = l, rr =N; - while(LL <=RR) - { - intMM = ll + RR >>1; A intnum = Query (1Mm1N1); + if(mm = = num + L && str[mm]! ='.') the { -L =mm; $ Break; the } the Else if(mm < num+l) LL = mm+1; the ElseRR = mm-1 ; the } - } in if(flag) R =l; the Else the { About if(R + tree[1] > N) r =N; the Else the { the intLL = r, rr =N; + while(LL <=RR) - { the intMM = ll + RR >>1;Bayi intnum = Query (1Mm1N1); the if(mm = = num + R && str[mm]! ='.') the { -R =mm; - Break; the } the Else if(mm < Num+r) LL = mm+1; the ElseRR = mm-1 ; the } - } the the } the if(L = = n+1)Continue;94 Else the { the intpos = (int) tmp[0] -'0'; theit =G[pos].begin ();98 while(It! =g[pos].end ()) About { - intindex = *it;101 if(Index >= L && index <= r && str[index]! ='.')102 {103Revise (index,1N1);104Str[index] ='.'; the }106 if(Index > R) Break;107it++;108 }109 } the }111 for(inti =1; I <= N; i++) the {113 if(Str[i]! ='.') thecout <<Str[i]; the } thecout <<Endl;117 return 0;118}View Code
Codeforces 889F Letters Removing (two points + segment Tree | | Tree-like array)