Gym-102141E

https://vjudge.net/problem/Gym-102141E

用set乱搞

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<set>
#include<cstring>
#define inf 2147483647
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(int i=a;i<=b;++i)

using namespace std;
char s[N];
int T,kase;
struct node{
    int l,r;
    bool operator < (const node &b) const{
        if(r!=b.r) return r<b.r;
            return l<b.l;
    }
};

struct tree{
    set<node>s;
    void init(){
        s.clear();
    }
    void insert(int l,int r){
        s.insert({l,r});
    }
    void spilt(int x){
        auto res=*s.lower_bound({-1,x});
        s.erase(res);
        if(x!=res.l) s.insert({res.l,x-1});
        if(x!=res.r) s.insert({x+1,res.r});
    }
    int query(int x){
        auto it=s.lower_bound({-1,x});
        return (it->r)-(it->l)+1;
    }
}a[26];

void in(int &x){
    int y=1;char c=getchar();x=0;
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    x*=y;
}
void o(int x){
    if(x<0){p('-');x=-x;}
    if(x>9)o(x/10);
    p(x%10+'0');
}

int main(){
    in(T);
    while(T--){
        scanf("%s",s);
        int n=strlen(s),op,q,x,l=0;
        For(i,0,25)
            a[i].init();
        For(i,1,n-1)
            if(s[i]!=s[i-1]){
                a[s[i-1]-'A'].insert(l,i-1);
                l=i;
            }
        a[s[n-1]-'A'].insert(l,n-1);
        in(q);
        printf("Case %d:\n",++kase);
        while(q--){
            in(op);in(x);
            if(op&1)
                o(a[s[x]-'A'].query(x)),p('\n');
            else
                a[s[x]-'A'].spilt(x),s[x]='#';
        }
    }
    return 0;
}

 

posted @ 2019-07-31 15:23  WeiAR  阅读(128)  评论(0编辑  收藏  举报