H CodeForces 159C String Manipulation 1.0

该题跟前面的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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值