String Manipulation 1.0

Time Limit: 3000ms
Memory Limit: 262144KB

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

<p< p="">

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 cici 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

<p< p="">

Print a single string — the user's final name after all changes are applied to it.

 

Sample Input

<p< p=""><p< p="">

Input
2
bac
3
2 a
1 b
2 c
Output
acb
Input
1
abacaba
4
1 a
1 a
1 c
2 b
Output
baa

Hint

<p< p="">

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的更多相关文章

  1. 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 ...

  2. string manipulation in game development-C # in Unity -

    ◇ string manipulation in game development-C # in Unity - It is about the various string ● defined as ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. String字符串补0操作常见方法

     String前补0 java的String字符串补0或空格 方法一:自己写的方法 /* *数字不足位数左补0** @param str* @param strLength*/public stati ...

  7. string 从下标0 一直截到倒数第三位

    StringUtils.substring(String.valueOf(maxSequence), 0, -3)如上,关键就是那个-3,表示倒数第三位.

  8. 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". ...

  9. CodeForces 779D. String Game(二分答案)

    题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...

随机推荐

  1. mybatis-generator-core快速生成实体类和Mapper

    日常使用Mybatis少不了和实体类和 Mapper 打交道.除了我们手写来实现,还可以使用 mybatis-generator-core 来快速生成 实体类和 Mapper. 步骤如下: 1.下载 ...

  2. 分享一个简单好用的ipv6正则表达式

    网上找了好几个,都不太好使.比较严谨的又运行缓慢,而且文本中多处含ipv6的时候,又提取不出全部的ipv6. 故分享一个不太严谨效率又高的ipv6正则表达式: ([a-f0-9]{1,4}(:[a-f ...

  3. [笔记-图论]Bellman-Ford

    用于求可带负权的单源有向图 优化后复杂度O(nm) 如果图中存在负环,就不存在最小路 这种情况下,就一定会有一个顶点被松弛多于n-1次,Bellman-Ford可直接判断出来 我在网上看到SPFA,发 ...

  4. db2部署

    下载地址: wget   ftp://public.dhe.ibm.com/software/hk/cobra/db2exc_970_LNX_x86_64.tar.gz 上传压缩包到/opt,再解压d ...

  5. python web开发 框架 模板 MVC

    我是跟着廖雪峰老师学习的,对于我这样的纯小白来说,跟着他的网站学习,简直是被妈妈抱在怀里一样无忧无虑,这样的学习本来没有记录下来的必要,但是由于我的粗心大意,经常会出现一些错误,所以我决定把这些错误记 ...

  6. Qt之图形(绘制文本)

    简述 前面我们讲解了Qt图形的基本绘制,其中包括: 绘制文本.直线.直线.矩形.弧线.椭圆.多边形.图片,以及其它一些高级用法,比如:渐变.转换等. 本节我们来详细讲解文字的绘制.主要通过QPaint ...

  7. 根据on,获取选中的元素

    打钩的元素有个on的class. // 礼物发送 function send_gift() { var type,diamond,name,id; var list = $('.live .on'); ...

  8. 字典(dictionary)与映射(map)

    1. 字典:key-value 键值对 反转字典:reverse_dict = dict(zip(D.values(), D.keys())) 前提要保证 D 的 value 不会出现重复,因为字典反 ...

  9. bind DNS搭建笔记

    设置默认网关 偶尔会出现问题 route add default gw 192.168.0.1 .vim /etc/sysctl.conf 这里是重点 配置路由转发,路由开启等都要用到. # Cont ...

  10. COGS 577 蝗灾 线段树+CDQ分治

    第一次写cdq分治 感谢hhd&lty 这20亿对CP的指导(逃) 其实 就是 递归看左半部分对右半部分的贡献 (树状数组写挂了--临时改的线段树[大写的尴尬]) //By SiriusRen ...