codeforce452DIV2——F. Letters Removing
题意:
给一个字符串和m个操作,每次给出l,r,c,把字符串中l-r这段区间的字符为c的字符删掉,求最后的字符串。(n,m<=2e5)
线段树。注意这个区间修改和普通区间修改的区别。
他们都是用树状数组做的哎,可是我对树状数组一直是一脸懵逼
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn=+;
const int maxnode=;
int n,m;
char s[maxn];
int a[maxn];
int get(char c){
if(c>='A'&&c<='Z')return c-'A';
if(c>='a'&&c<='z')return c-'a'+;
if(c>=''&&c<='')return c-''+;
}
char res(int x){
if(x>=&&x<)return x+'A';
if(x>=&&x<)return x-+'a';
if(x>=&&x<)return x-+'';
}
int sumv[*maxn],num[*maxn][maxnode];
void build(int o,int L,int R){
if(L==R){
sumv[o]=;
num[o][a[L]]=;
return ;
}
int M=L+(R-L)/;
build(*o,L,M);
build(*o+,M+,R);
sumv[o]=sumv[*o]+sumv[*o+];
for(int i=;i<;i++)
num[o][i]=num[*o][i]+num[*o+][i];
}
int ql,qr,c;
void update(int o,int L,int R){
if(num[o][c]==)return ;
if(ql>R||qr<L)
return ;
if(L==R){
if(num[o][c]){
sumv[o]=;
num[o][c]=;
}
return ;
}
int M=L+(R-L)/;
update(*o,L,M);
update(*o+,M+,R);
sumv[o]=sumv[*o]+sumv[*o+];
num[o][c]=num[*o][c]+num[*o+][c];
}
int find(int o,int L,int R ,int k){
int M=L+(R-L)/;
if(L==R)return L;
if(sumv[*o]>=k)return find(*o,L,M,k);
else return find(*o+,M+,R,k-sumv[*o]);
}
void tra(int o,int L,int R){
if(sumv[o]==)return ;
if(L==R){
for(int i=;i<;i++)
if(num[o][i]){
int c=res(i);
printf("%c",c);
}
return ;
}
int M=L+(R-L)/;
tra(*o,L,M);
tra(*o+,M+,R);
}
int main(){
scanf("%d%d",&n,&m);
scanf("%s",s+);
for(int i=;i<=n;i++)a[i]=get(s[i]);
build(,,n);
int L,R;
char cc;
for(int i=;i<=m;i++){
scanf("%d%d %c",&L,&R,&cc);
L=find(,,n,L),R=find(,,n,R);
ql=L,qr=R,c=get(cc);
update(,,n);
}
tra(,,n);
return ;
}
codeforce452DIV2——F. Letters Removing的更多相关文章
- 【CodeForces】899 F. Letters Removing
[题目]F. Letters Removing [题意]给定只含小写字母.大写字母和数字的字符串,每次给定一个范围要求删除[l,r]内的字符c(l和r具体位置随删除变动),求m次操作后的字符串.n&l ...
- Codeforces 899 F. Letters Removing (二分、树状数组)
题目链接:Letters Removing 题意: 给你一个长度为n的字符串,给出m次操作.每次操作给出一个l,r和一个字符c,要求删除字符串l到r之间所有的c. 题解: 看样例可以看出,这题最大的难 ...
- Codeforces Round #452 F. Letters Removing
Description Petya has a string of length n consisting of small and large English letters and digits. ...
- codeforces 899F Letters Removing set+树状数组
F. Letters Removing time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 899F - Letters Removing
Codeforces 899F - Letters Removing 思路:考虑一下怎么找到输入的l和r在原来串中的位置,我们想到用前缀和来找,一开始所有位置都为1,删掉后为0,那么前缀和为l的位置就 ...
- Codeforces 889F Letters Removing(二分 + 线段树 || 树状数组)
Letters Removing 题意:给你一个长度为n的字符串,然后进行m次删除操作,每次删除区间[l,r]内的某个字符,删除后并且将字符串往前补位,求删除完之后的字符串. 题解:先开80个set ...
- Letters Removing CodeForces - 899F (线段树维护序列)
大意: 给定字符串, 每次删除一段区间的某种字符, 最后输出序列. 类似于splay维护序列. 每次删除都会影响到后面字符的位置 可以通过转化为查询前缀和=k来查找下标. #include <i ...
- CF899F. Letters Removing
给一个字符串支持以下操作:区间删除某个特定字符.最后输出字符串.n,m<=200000. 这题我居然不会可以回家了.. 首先,单点删除,选个平衡树比如set. 然后,他给的下标是会随删除操作变化 ...
- Codeforces 899F Letters Removing 线段树/树状数组
虽然每次给一个区间,但是可以看作在区间内进行数个点操作,同样数列下标是动态变化的,如果我们将每个字符出现看作1,被删除看作0,则通过统计前缀和就能轻松计算出两个端点的位置了!这正是经典的树状数组操作 ...
随机推荐
- WWDC 2017, 让我们看看 iTunesConnect 有了哪些不同
距离 WWDC 2017 过去已经有 7 天了,小伙伴们是不是已经发现我们的苹果后台和之前的界面有些略微的不同,如果有心的朋友下了 iOS 11 beta 版就会发现设备上的 App Store 界面 ...
- cmd 操作WinService
1.运行--〉cmd:打开cmd命令框 2.在命令行里定位到InstallUtil.exe所在的位置 InstallUtil.exe 默认的安装位置是在C:\Windows\Microsoft.NET ...
- 人生苦短之我用Python篇(基础)
Python简介 Python,是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum于1989年发明,第一个公开发行版发行于1991年. Python是纯粹的自由软件, ...
- NETCore中RabbitMQ的使用
NET中RabbitMQ的使用 https://www.cnblogs.com/xibei666/p/5931267.html 概述 MQ全称为Message Queue, 消息队列(MQ)是一种应用 ...
- 数据库模式显示的Swing表格
http://code.google.com/p/simpleframework/ 是一个国内开源的JavaWeb框架,但其net.simpleframework.swing包里面提供了一个超强的Sw ...
- 在django中使用logging
转:http://www.tuicool.com/articles/IV3meeE logging django使用python的内置模块logging来管理自己的日志,logging中四个重要的概念 ...
- button和input type=button的区别及注意事项
<button>标签 定义和用法 <button>标签定义一个按钮. 在button元素内部,您可以放置内容,比如文本或图像.这是该元素与使用input元素创建的按钮之间的不同 ...
- oracle truncate闪回数据库恢复
1.创建试验表 conn scott/tiger create table truncate_test as select * from user_objects; select count(*) f ...
- RbbitMQ基础知识
MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们.消息传递指的是程序之间 ...
- Linux 配置静态Ip地址
注:所有红色字体标注均为 Linux 的 操作命令 ! 1, 使用root账户登录系统 2, 可以先使用 ifconfig : 查看网卡信息 eth0 为默认的第一个网卡 , 如果有第二个就会显示 ...