CodeForces 159c String Manipulation 1.0

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

2bac32 a1 b2 c

Output

acb

Input

1abacaba41 a1 a1 c2 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

VK Cup 2012 Qualification Round 2

解题:直接用线段树记录二十六个字母分别的出现位置。。。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 200010;
 4 int tree[26][maxn<<2],k,n,p;
 5 bool isdel[maxn];
 6 string str,s,c;
 7 void pushup(int wd,int v) {
 8     tree[wd][v] = tree[wd][v<<1] + tree[wd][v<<1|1];
 9 }
10 void update(int L,int R,int wd,int id,int v) {
11     if(L == R) {
12         tree[wd][v]++;
13         return;
14     }
15     int mid = (L + R)>>1;
16     if(id <= mid) update(L,mid,wd,id,v<<1);
17     if(id > mid) update(mid+1,R,wd,id,v<<1|1);
18     pushup(wd,v);
19 }
20 void del(int L,int R,int wd,int v,int rk){
21     if(L == R) {
22         tree[wd][v]--;
23         isdel[L] = true;
24         return;
25     }
26     int mid = (L + R)>>1;
27     if(tree[wd][v<<1] >= rk) del(L,mid,wd,v<<1,rk);
28     else del(mid+1,R,wd,v<<1|1,rk-tree[wd][v<<1]);
29     pushup(wd,v);
30 }
31 int main() {
32     cin.sync_with_stdio(false);
33     cin>>k>>s>>n;
34     str = "";
35     for(int i = 0; i < k; ++i) str += s;
36     int len = str.length();
37     for(int  i = 0; i < len; ++i)
38         update(0,len-1,str[i]-‘a‘,i,1);
39     while(n--){
40         cin>>p>>c;
41         del(0,len-1,c[0]-‘a‘,1,p);
42     }
43     for(int i = 0; i < len; ++i)
44         if(!isdel[i]) cout<<str[i];
45     cout<<endl;
46     return 0;
47 }

时间: 2024-08-19 03:00:09

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/problem/91/B Description One popular website developed an unusual username editing procedure. One can change the username only by deleting some characte

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 with its value. This feature of shell is called parameter expansion. But parameter expansion has numerous other forms which allow you to expand a parame

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

String前补0 java的String字符串补0或空格 方法一:自己写的方法 /* *数字不足位数左补0** @param str* @param strLength*/public static String addZeroForNum(String str, int strLength) {int strLen = str.length();if (strLen < strLength) {while (strLen < strLength) {StringBuffer sb = ne

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

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

Codeforces 118A String Task

题目链接 http://codeforces.com/problemset/problem/118/A #include<iostream> #include<string> #include<cctype> #include<algorithm> using namespace std; int main() { string str; cin>>str; int i; //将代码变成小写 transform(str.begin(), str.

关于new String(new byte[]{0})

今天在做Zxing的二维码的时候,返回的数据竟然是这个样子,郁闷了一小会,说明我用的这个控件有改进的空间.由于时间的原因,最后还是把这个返回的字符串重新组装. 1 Bundle bundle = data.getExtras(); 2 byte[] btyeAry = bundle.getString("result").getBytes(); 3 StringBuffer buffer = new StringBuffer(); 4 if(btyeAry != null &&

Codeforces C - String Reconstruction

C - String Reconstruction 方法一:把确定的点的父亲节点设为下一个点,这样访问过的点的根节点都是没访问过的点. 代码: #include<bits/stdc++.h> using namespace std; const int N=1e6+5; char s[N],res[N*2]; int fa[N*2]; int Find(int x) { return x==fa[x]?x:fa[x]=Find(fa[x]); } int main() { for(int i=

Java String字符串补0或空格

原文:http://www.open-open.com/code/view/1471488086408 package cn.com.songjy; import java.text.NumberFormat; //Java 中给数字左边补0 public class NumberFormatTest { public static void main(String[] args) { // 待测试数据 int i = 1; // 得到一个NumberFormat的实例 NumberFormat

CodeForces 828C String Reconstruction(并查集思想)

题意:给你n个串,给你每个串在总串中开始的每个位置,问你最小字典序总串. 思路:显然这道题有很多重复填涂的地方,那么这里的时间花费就会特别高. 我们维护一个并查集fa,用fa[i]记录从第i位置开始第一个没填涂的位置,那每次都能跳过涂过的地方.每次填完当前格就去填find(fa[i + 1]). ps:一定要合并,不然超时. 代码: #include<stack> #include<vector> #include<queue> #include<set>