该题跟前面的POJ 2886蛮像的·~给出了相对位置·~处理处绝对位置就好了·~
因为空间问题。。所以建了26个树状数组,然后二分找答案即可
/*===============*\
| *** *** *** *** |
| * ** * * * |
| *** *** * *** |
| ID: ZERO |
| LANG: C++ |
\*===============*/
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>
#include <cassert>
using namespace std;
#define maxn 200001
#define mod (int)(1e9+7)
int tree[28][maxn];
int lowbit(int x){
return x&(-x);
}
void add(int x,int v,int *arr){
while(x<=maxn-1){
arr[x]+=v;
x+=lowbit(x);
}
}
int sumit(int x,int *arr){
int sum=0;
while(x>0){
sum+=arr[x];
x-=lowbit(x);
}
return sum;
}
int find(int nn,int *arr,int ll,int rr){
int l,r,ans;
l=ll,r=rr;
int mid=(l+r)/2;
while(r>l+1){
mid=(l+r)/2;
ans=sumit(mid,arr);
if(ans>nn) r=mid-1;
else if(ans<nn)l=mid+1;
else r=mid;
}
if(sumit(l,arr)==nn) return l;
if(sumit(mid,arr)==nn) return mid;
return r;
}
char s[maxn];
int main(){
int i,j,k;
while(~scanf("%d",&k)){
scanf("%s",s);
int len=strlen(s);
int n;
scanf("%d",&n);
for(i=0;i<k;i++){
for(j=0;j<len;j++){
add(i*len+j+1,1,tree[s[j]-'a']);
s[i*len+j]=s[j];
}
}
char temp[2];
int nn;
while(n--){
scanf("%d%s",&nn,temp);
int now=find(nn,tree[temp[0]-'a'],1,k*len);//二分找绝对位置
s[now-1]=0;//标记掉该点
add(now,-1,tree[temp[0]-'a']);//相应在数组中减掉该点
}
for(i=0;i<k*len;i++){
if(s[i]) printf("%c",s[i]);//未标记则输出
}
printf("\n");
}
return 0;
}