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

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

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

#include <iostream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
using namespace std; const int N = 2e5+10;
int n, m;
char s[N];
int tr[63][N<<2];
bool vis[63][N<<2];
inline void pu(int o) {
REP(i,1,62) tr[i][o]=tr[i][lc]+tr[i][rc];
}
inline void pd(int o) {
REP(i,1,62) if (vis[i][o]) {
tr[i][lc]=0,vis[i][lc]=1;
tr[i][rc]=0,vis[i][rc]=1;
vis[i][0]=0;
}
}
int get(char x) {
if ('0'<=x&&x<='9') return x-'0'+1;
if ('A'<=x&&x<='Z') return x-'A'+11;
return x-'a'+37;
}
void build(int o, int l, int r) {
if (l==r) ++tr[get(s[l])][o];
else build(ls),build(rs),pu(o);
}
int find(int o, int l, int r, int k) {
if (l==r) return l;
int s = 0;
REP(i,1,62) {
if (vis[i][o]) {
tr[i][lc]=0,vis[i][lc]=1;
tr[i][rc]=0,vis[i][rc]=1;
vis[i][o]=0;
}
else s+=tr[i][lc];
}
if (s>=k) return find(ls,k);
return find(rs,k-s);
}
void update(int o, int l, int r, int ql, int qr, int v) {
if (ql<=l&&r<=qr) return tr[v][o]=0,vis[v][o]=1,void();
pd(o);
if (mid>=ql) update(ls,ql,qr,v);
if (mid<qr) update(rs,ql,qr,v);
pu(o);
}
void dfs(int o, int l, int r) {
if (l==r) {
if (tr[get(s[l])][o]) printf("%c", s[l]);
}
else pd(o),dfs(ls),dfs(rs);
}
int main() {
scanf("%d%d%s", &n, &m, s+1);
build(1,1,n);
REP(i,1,m) {
int l, r;
char c;
scanf("%d%d %c", &l, &r, &c);
l=find(1,1,n,l),r=find(1,1,n,r);
update(1,1,n,l,r,get(c));
}
dfs(1,1,n);hr;
}

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. java操作对比两个字符串,将差异数据提取出来

    记录瞬间 在实际的工作中,需要解决生成两次字符串结果进行对比的问题,将存在差异的字符串直接给出来. 当然,前提是需要将对比的两次结果,进行前期处理 比如: a_str = "@com/ene ...

  2. decimal(19,6)什么意思

    decimal(19,6)什么意思 数字长度19位,精确到小数点后6位例如0.123456 mysql中varchar(50)最多能存多少个汉字 首先要确定mysql版本4.0版本以下,varchar ...

  3. -bash: belts.awk: command not found

    执行awk命令时,没有问题.可是执行awk脚本时,出现这个问题:-bash: belts.awk: command not found. 既然之前直接执行awk命令没有问题,说明awk已经装了,本身是 ...

  4. 3、SpringBoot集成Storm WorldCount

    RandomSentenceSpout //数据源,在已知的英文句子中,随机发送一条句子出去. public class RandomSentenceSpout extends BaseRichSpo ...

  5. ORACLE 12c RAC的常用管理命令

    ORACLE 12c RAC的常用管理命令 一.查询 1.RAC查询 1.1.查询节点 [grid@swnode1 ~]$ su - grid [grid@swnode1 ~]$ /u01/app/1 ...

  6. VMware虚拟机扩展Ubuntu系统磁盘空间

    1 首先给虚拟机扩容 虚拟机->设置->硬盘->实用程序->扩展磁盘容量 2 启动Ubuntu系统 2.1 打开终端安装gparted,sudo apt-get install ...

  7. 微信小程序云开发更换云开发环境

    小程序云开发环境初始化默认是第一个环境,但是我们可以指定环境id //app.js App({ onLaunch: function () { if (!wx.cloud) { console.err ...

  8. 安装vue-cli-service和webpack

    https://www.zacms.com/index.php/archives/106/ http://www.cnblogs.com/sloong/p/5584684.html

  9. [IoC容器Unity]第一回:Unity预览

    1.引言 高内聚,低耦合成为一个OO架构设计的一个参考标准.高内聚是一个模块或者一个类中成员跟这个模块或者类的关系尽量高,低耦合是不同模块或者不同类之间关系尽量简单. 拿咱国家举例来说,假如你是中国人 ...

  10. 【python 3】 字典方法操作汇总

    基础数据类型:tuple 1.1  新增 dic["key"] = value                            字典中没有key就添加,有key就覆盖 dic ...