Codeforces #452 Div2 F
#452 Div2 F
题意
给出一个字符串, m 次操作,每次删除区间 \([l,r]\) 之间的字符 \(c\) ,输出最后得到的字符串。
分析
通过树状数组和二分,我们可以把给定的区间对应到在起始字符串上的区间。
然后暴力去删字符即可(因为最多只会删掉等同于字符串长度的字符个数),总共只有 62 种字符,set 维护下位置。
code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4e5 + 10;
int n, m, f[N];
void update(int x) {
for(int i = x; i < N; i += i & -i) f[i]--;
}
int query(int x) {
int s = 0;
for(int i = x; i; i -= i & -i) s += f[i];
return s;
}
int fd(int x) {
int l = 1, r = n, mid;
while(l < r) {
mid = l + r >> 1;
if(query(mid) < x) l = mid + 1;
else r = mid;
}
return l;
}
char s[N];
set<int> S[150];
char ans[N];
int main() {
scanf("%d%d", &n, &m);
scanf("%s", s + 1);
for(int i = 1; i <= n; i++) {
S[s[i]].insert(i);
f[i + (i & -i)] += ++f[i];
}
while(m--) {
char c[2];
int l, r;
scanf("%d%d%s", &l, &r, c);
l = fd(l);
r = fd(r);
auto it = S[c[0]].lower_bound(l);
while(it != S[c[0]].end() && *it <= r) {
update(*it);
auto itt = it;
it++;
S[c[0]].erase(itt);
}
}
for(int i = 0; i < 150; i++) {
for(int j : S[i]) ans[j] = i;
}
for(int i = 1; i <= n; i++) {
if(ans[i]) cout << ans[i];
}
return 0;
}
Codeforces #452 Div2 F的更多相关文章
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #451 Div2 F
#451 Div2 F 题意 给出一个由数字组成的字符串,要求添加一个加号和等号,满足数字无前导 0 且等式成立. 分析 对于这种只有数字的字符串,可以快速计算某一区间的字符串变成数字后并取模的值,首 ...
- Codeforces #442 Div2 F
#442 Div2 F 题意 给出一些包含两种类型(a, b)问题的问题册,每本问题册有一些题目,每次查询某一区间,问有多少子区间中 a 问题的数量等于 b 问题的数量加 \(k\) . 分析 令包含 ...
- Codeforces #528 Div2 F (1087F) Rock-Paper-Scissors Champion 树状数组+set
题意:n个人站成一排,初始时刻每个人手中都有一个图案,可能是石头,剪刀,布3个中的1种,之后会随机选取相邻的两个人玩石头剪刀布的游戏,输的人会离开(如果两个人图案相同,则随机选择一个人离开).执行(n ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
随机推荐
- strus2项目中百度编辑器运用的几点细节
百度编辑器的运用可以参考我之前写的一篇文章,在java项目中加入百度富文本编辑器.这篇文章是以maven+spring mvc项目进行的,总得来说配置比较简单,但是如果是想在strus2项目中配置ue ...
- (转)Maven依赖的jar包下载不了、jar更新不了的解决办法
场景一: 使用Maven的同学可能偶尔会遇到这种情况:pom.xml中依赖了项目需要的某个jar文件,但是使用Maven –> update project 还是没办法下载该jar到项目中,你可 ...
- flask开发没有解决的bug记录
sqlalchemy.exc.InvalidRequestError sqlalchemy.exc.InvalidRequestError: This Session's transaction ha ...
- CS:APP3e 深入理解计算机系统_3e Attacklab 实验
详细的题目要求和资源可以到 http://csapp.cs.cmu.edu/3e/labs.html 或者 http://www.cs.cmu.edu/~./213/schedule.html 获取. ...
- 前端MVC Vue2学习总结(二)——Vue的实例、生命周期与Vue脚手架(vue-cli)
一.Vue的实例 1.1.创建一个 Vue 的实例 每个 Vue 应用都是通过 Vue 函数创建一个新的 Vue 实例开始的: var vm = new Vue({ // 选项 }) 虽然没有完全遵循 ...
- presto
presto中文站:http://prestodb-china.com/ 进入hadoop机器,进入presto所在bin目录:presto --server localhost:9090 --cat ...
- android 网络请求Volley的简单使用
下载到本地jar包或者在线导入,jar地址:链接:http://pan.baidu.com/s/1gf3VZAb 密码:mmye //定义变量 private RequestQueue mQueue= ...
- xamarin android listview的用法
listview也许是用的非常频繁的一个控件之一,下面我写一个xamarin的listview栗子,大家尝一尝xamarin android开发的乐趣.原谅我的大小写吧. listview绑定自定义的 ...
- nginx php上传配置
.file_uploads 设为On,允许通过HTTP上传文件 2.upload_tmp_dir 文件上传至服务器时用于临时存储的目录,如果没指定,系统会使用默认的临时文件夹(我的机器是/tmp). ...
- nginx在 window下 自动退出 php-cgi
win32+nginx+php自动挂掉php-cgi.exe RunHiddenConsole E:/wnmp/php5/php-cgi.exe -b 127.0.0.1:9000 -c &qu ...