大意: 给定字符串, 每次删除一段区间的某种字符, 最后输出序列.

类似于splay维护序列. 每次删除都会影响到后面字符的位置

可以通过转化为查询前缀和=k来查找下标.

  1. #include <iostream>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <cstdio>
  5. #include <math.h>
  6. #include <set>
  7. #include <map>
  8. #include <queue>
  9. #include <string>
  10. #include <string.h>
  11. #include <bitset>
  12. #define REP(i,a,n) for(int i=a;i<=n;++i)
  13. #define PER(i,a,n) for(int i=n;i>=a;--i)
  14. #define hr putchar(10)
  15. #define pb push_back
  16. #define lc (o<<1)
  17. #define rc (lc|1)
  18. #define mid ((l+r)>>1)
  19. #define ls lc,l,mid
  20. #define rs rc,mid+1,r
  21. using namespace std;
  22.  
  23. const int N = 2e5+10;
  24. int n, m;
  25. char s[N];
  26. int tr[63][N<<2];
  27. bool vis[63][N<<2];
  28. inline void pu(int o) {
  29. REP(i,1,62) tr[i][o]=tr[i][lc]+tr[i][rc];
  30. }
  31. inline void pd(int o) {
  32. REP(i,1,62) if (vis[i][o]) {
  33. tr[i][lc]=0,vis[i][lc]=1;
  34. tr[i][rc]=0,vis[i][rc]=1;
  35. vis[i][0]=0;
  36. }
  37. }
  38. int get(char x) {
  39. if ('0'<=x&&x<='9') return x-'0'+1;
  40. if ('A'<=x&&x<='Z') return x-'A'+11;
  41. return x-'a'+37;
  42. }
  43. void build(int o, int l, int r) {
  44. if (l==r) ++tr[get(s[l])][o];
  45. else build(ls),build(rs),pu(o);
  46. }
  47. int find(int o, int l, int r, int k) {
  48. if (l==r) return l;
  49. int s = 0;
  50. REP(i,1,62) {
  51. if (vis[i][o]) {
  52. tr[i][lc]=0,vis[i][lc]=1;
  53. tr[i][rc]=0,vis[i][rc]=1;
  54. vis[i][o]=0;
  55. }
  56. else s+=tr[i][lc];
  57. }
  58. if (s>=k) return find(ls,k);
  59. return find(rs,k-s);
  60. }
  61. void update(int o, int l, int r, int ql, int qr, int v) {
  62. if (ql<=l&&r<=qr) return tr[v][o]=0,vis[v][o]=1,void();
  63. pd(o);
  64. if (mid>=ql) update(ls,ql,qr,v);
  65. if (mid<qr) update(rs,ql,qr,v);
  66. pu(o);
  67. }
  68. void dfs(int o, int l, int r) {
  69. if (l==r) {
  70. if (tr[get(s[l])][o]) printf("%c", s[l]);
  71. }
  72. else pd(o),dfs(ls),dfs(rs);
  73. }
  74. int main() {
  75. scanf("%d%d%s", &n, &m, s+1);
  76. build(1,1,n);
  77. REP(i,1,m) {
  78. int l, r;
  79. char c;
  80. scanf("%d%d %c", &l, &r, &c);
  81. l=find(1,1,n,l),r=find(1,1,n,r);
  82. update(1,1,n,l,r,get(c));
  83. }
  84. dfs(1,1,n);hr;
  85. }

Letters Removing CodeForces - 899F (线段树维护序列)的更多相关文章

  1. CodeForces 343D 线段树维护dfs序

    给定一棵树,初始时树为空 操作1,往某个结点注水,那么该结点的子树都注满了水 操作2,将某个结点的水放空,那么该结点的父亲的水也就放空了 操作3,询问某个点是否有水 我们将树进行dfs, 生成in[u ...

  2. Codeforces 889F Letters Removing(二分 + 线段树 || 树状数组)

    Letters Removing 题意:给你一个长度为n的字符串,然后进行m次删除操作,每次删除区间[l,r]内的某个字符,删除后并且将字符串往前补位,求删除完之后的字符串. 题解:先开80个set ...

  3. Tree Generator™ CodeForces - 1149C (线段树,括号序列)

    大意: 给定括号序列, 每次询问交换两个括号, 求括号树的直径. 用[ZJOI2007]捉迷藏的方法维护即可. #include <iostream> #include <algor ...

  4. 【bzoj4712】洪水 树链剖分+线段树维护树形动态dp

    题目描述 给出一棵树,点有点权.多次增加某个点的点权,并在某一棵子树中询问:选出若干个节点,使得每个叶子节点到根节点的路径上至少有一个节点被选择,求选出的点的点权和的最小值. 输入 输入文件第一行包含 ...

  5. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

  6. Codeforces GYM 100114 D. Selection 线段树维护DP

    D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...

  7. Codeforces 834D The Bakery【dp+线段树维护+lazy】

    D. The Bakery time limit per test:2.5 seconds memory limit per test:256 megabytes input:standard inp ...

  8. [Codeforces]817F. MEX Queries 离散化+线段树维护

    [Codeforces]817F. MEX Queries You are given a set of integer numbers, initially it is empty. You sho ...

  9. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

随机推荐

  1. Vue相关开源项目库汇总

    https://github.com/opendigg/awesome-github-vue http://www.opendigg.com/tags/front-vue README.md 内容 U ...

  2. 接口自动化测试持续集成--Soapui接口功能测试参数化

    按照自动化测试分层实现的原理,每一层的脚本实现都要进行参数化,自动化的目标就是要实现脚本代码与测试数据分离. 当测试数据进行调整的时候不会对脚本的实现带来震荡,从而提高脚本的稳定性与灵活度,降低脚本的 ...

  3. 201902<<百岁人生>>

    过年的那段时间,在家看到公司推荐的10本2019年必读书籍,里面有这本书,于是就开始了.... 第一次这么认真的看这类书籍,看完之后感触颇多,毕竟这个问题我从没思考过,很少站在这样的高度去看所有方方面 ...

  4. 记录心得-FastJson分层解析demo示例

    记录一下,平时用到,可速查!关键: // startArray(); 开始解析数组 // endArray(); 结束解析数组 // startObject(); 开始解析键值对 // endObje ...

  5. flask 电子邮件进阶实践-用模板发送163邮件

    电子邮件进阶实践 下面来学习构建邮件的HTML正文,并使用模板组织内容. 一封电子邮件的正文可以是纯文本(text/plain),也可以是HTML格式的文本(text/html).处于全面的考虑,一封 ...

  6. for 循环,如果判断那里用到了一个函数,每次循环一次都会调用一次函数,如图

    但用高级for,可以不用每次都调用方法

  7. CodeForces - 1033A

    Alice and Bob are playing chess on a huge chessboard with dimensions n×nn×n. Alice has a single piec ...

  8. jquery serializeArray()、serialize()增加数据

    转自:http://blog.csdn.net/csdnzhangtao5/article/details/52981541 serialize().serializeArray()方法都是jquer ...

  9. 翻译 | Placing Search in Context The Concept Revisited

    翻译 | Placing Search in Context The Concept Revisited 原文 摘要 [1] Keyword-based search engines are in w ...

  10. mysql批量更新数据

    CREATE PROCEDURE `sp_update_temp_data`( out po_returnvalue ) ) leave_top:BEGIN #Routine body goes he ...