CodeForces 159c String Manipulation 1.0
String Manipulation 1.0
This problem will be judged on CodeForces. Original ID: 159C
64-bit integer IO format: %I64d Java class name: (Any)
One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name s, a user can pick number p and character c and delete the p-th occurrence of character c from the name. After the user changed his name, he can't undo the change.
For example, one can change name "arca" by removing the second occurrence of character "a" to get "arc".
Polycarpus learned that some user initially registered under nickname t, where t is a concatenation of k copies of string s. Also, Polycarpus knows the sequence of this user's name changes. Help Polycarpus figure out the user's final name.
Input
The first line contains an integer k (1 ≤ k ≤ 2000). The second line contains a non-empty string s, consisting of lowercase Latin letters, at most 100characters long. The third line contains an integer n (0 ≤ n ≤ 20000) — the number of username changes. Each of the next n lines contains the actual changes, one per line. The changes are written as "pi ci" (without the quotes), where pi (1 ≤ pi ≤ 200000) is the number of occurrences of letter ci, ci is a lowercase Latin letter. It is guaranteed that the operations are correct, that is, the letter to be deleted always exists, and after all operations not all letters are deleted from the name. The letters' occurrences are numbered starting from 1.
Output
Print a single string — the user's final name after all changes are applied to it.
Sample Input
2
bac
3
2 a
1 b
2 c
acb
1
abacaba
4
1 a
1 a
1 c
2 b
baa
Hint
Let's consider the first sample. Initially we have name "bacbac"; the first operation transforms it into "bacbc", the second one — to "acbc", and finally, the third one transforms it into "acb".
Source
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int tree[][maxn<<],k,n,p;
bool isdel[maxn];
string str,s,c;
void pushup(int wd,int v) {
tree[wd][v] = tree[wd][v<<] + tree[wd][v<<|];
}
void update(int L,int R,int wd,int id,int v) {
if(L == R) {
tree[wd][v]++;
return;
}
int mid = (L + R)>>;
if(id <= mid) update(L,mid,wd,id,v<<);
if(id > mid) update(mid+,R,wd,id,v<<|);
pushup(wd,v);
}
void del(int L,int R,int wd,int v,int rk){
if(L == R) {
tree[wd][v]--;
isdel[L] = true;
return;
}
int mid = (L + R)>>;
if(tree[wd][v<<] >= rk) del(L,mid,wd,v<<,rk);
else del(mid+,R,wd,v<<|,rk-tree[wd][v<<]);
pushup(wd,v);
}
int main() {
cin.sync_with_stdio(false);
cin>>k>>s>>n;
str = "";
for(int i = ; i < k; ++i) str += s;
int len = str.length();
for(int i = ; i < len; ++i)
update(,len-,str[i]-'a',i,);
while(n--){
cin>>p>>c;
del(,len-,c[]-'a',,p);
}
for(int i = ; i < len; ++i)
if(!isdel[i]) cout<<str[i];
cout<<endl;
return ;
}
CodeForces 159c String Manipulation 1.0的更多相关文章
- VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0 字符串模拟
C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/pr ...
- string manipulation in game development-C # in Unity -
◇ string manipulation in game development-C # in Unity - It is about the various string ● defined as ...
- Entity Framework 6 执行Linq to Entities异常"p__linq__1 : String truncation: max=0, len=2, value='测试'"
场景再现 我需要查询公司名称包含给定字符串的公司,于是我写了下面的测试小例子: var condition = "测试"; var query = from b in db.Com ...
- Bash String Manipulation Examples – Length, Substring, Find and Replace--reference
In bash shell, when you use a dollar sign followed by a variable name, shell expands the variable wi ...
- weblogic部署异常: cvc-enumeration-valid: string value '3.0' is not a valid enumeration value for web-app-versionType in namespace http://java.sun.com/xml/ns/javaee:<null>
尝试使用weblogic部署一个Demo应用,在选择应用目录后,报出下面的异常: VALIDATION PROBLEMS WERE FOUND problem: cvc-enumeration-val ...
- String字符串补0操作常见方法
String前补0 java的String字符串补0或空格 方法一:自己写的方法 /* *数字不足位数左补0** @param str* @param strLength*/public stati ...
- string 从下标0 一直截到倒数第三位
StringUtils.substring(String.valueOf(maxSequence), 0, -3)如上,关键就是那个-3,表示倒数第三位.
- vue.esm.js?efeb:628 [Vue warn]: Invalid prop: type check failed for prop "defaultActive". Expected String with value "0", got Number with value 0.
vue.esm.js?efeb:628 [Vue warn]: Invalid prop: type check failed for prop "defaultActive". ...
- CodeForces 779D. String Game(二分答案)
题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...
随机推荐
- Tiles入门及项目实战
1.Apache Tiles™ Apache Tiles是一个模板布局框架.最初是为了简化Web应用界面开发,如今已不限于JavaEE Web环境. Tiles允许开发人员定义页面片段,它们在运行时会 ...
- [笔记-统计学习方法]感知机模型(perceptron) 原理与实现
前几天认把感知机这一章读完了,顺带做了点笔记 现在把笔记做第三次的整理 (不得不说博客园的LaTex公式和markdown排版真的不太舒服,该考虑在服务器上建一个博客了) 零.总结 适用于具有线性可分 ...
- poj2728 Desert King(最小生成树+01分数规划=最优比率生成树)
题意 n个点完全图,每个边有两个权值,求分数规划要求的东西的最小值. (n<=1000) 题解 心态炸了. 堆优化primT了. 普通的就过了. 我再也不写prim了!!!! 咳咳 最优比率生成 ...
- Unity C# 设计模式(三)工厂方法模式
定义: 定义一个创建对象的接口(父类),由子类决定需要实例化哪一个类. 这样,核心工厂类成为了一个抽象角色,不再负责产品的创建,仅提供具体工厂类所必须实现的接口,这样进一步抽象化的好处是使得工厂方法模 ...
- Unity ContextMenu特性
有时候我们需要在编辑器下,频繁的做一些操作,比如说在不同的位置创建物体,一个个的修改坐标显然有点繁琐 这时候ContextMenu就派上用处了 例:利用 LineRenderer 画圆,我们不可能一个 ...
- 【Henu ACM Round#16 E】Paths and Trees
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 感觉很像一道最短路. 然后就试了一发. 结果真的是.. 只要用一个优先队列优化的dijkstra算法求出每个点的最短路上的前一个点是 ...
- 洛谷—— P1969 积木大赛
https://www.luogu.org/problem/show?pid=1969 题目描述 春春幼儿园举办了一年一度的“积木大赛”.今年比赛的内容是搭建一座宽度为n的大厦,大厦可以看成由n块宽度 ...
- 使用glPushMatrix和glPopMatrix的原因
转自 百度百科 glPushMatrix 函数将当前矩阵堆栈推送,通过一个,复制当前矩阵. 这就是后 glPushMatrix 的调用堆栈的顶部矩阵是它下面的相同的. 1. 原理讲解 终于明白 ...
- 并查集树数据结构hdu1325
我的解法就是去构造了一棵树 以数组的存储方式 数组的值存放节点的根. 排除空树 剩下的就是出现环和多根节点的情况 也就是排除森林和有一个节点多个入度的情况 排除森林就用到了并查集 也就是便利数组让其仅 ...
- Azure 配置高可用的准备系列工作-建立不同区域的存储账户和建立网络!
我们谈到我们的业务,常常谈到一个词.三层架构,就是我们的UI层.数据訪问层和数据存储层的分离,通常情况下我们的业务高可用必须满足这三层的所有高可用的情况下才干达到最高级别的高可用. 那么谈到Az ...