码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces打完补题

时间:2019-10-02 11:04:47      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:problem   线段   ble   com   lower   std   一个   ORC   ios   

https://codeforces.com/contest/1234/problem/D

写了个巨蠢的线段树(不愧是垃圾),有必要提醒下自己这种题怎么做

#include<iostream>
#include<cstdio>
#include<string>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 32;
set<int> st[maxn];
int main()
{
    string words;
    cin>>words;
    words = ‘.‘ + words;
    int len = words.size() - 1;
    for(int i=1;i<=len;++i)
        st[words[i]-‘a‘].insert(i);
    int q,cmd,pos,l,r;
    char ch;  scanf("%d",&q);
    for(int k=0;k!=q;++k)
    {
        scanf("%d",&cmd);
        if(cmd==1)
        {
            scanf("%d",&pos);
            getchar();
            scanf("%c",&ch);
            st[words[pos]-‘a‘].erase(pos);
            words[pos] = ch;
            st[words[pos]-‘a‘].insert(pos);
        }else{
            int ans = 0;
            scanf("%d%d",&l,&r);
            for(int i=0;i!=26;++i)
            {
                auto it = st[i].lower_bound(l);//MDZZ 再也不直接用algorithm的二分了,容器内的快多了,佛了
                if(it == st[i].end())
                    continue;//找到大于等于l开始的字符,因为不重复,所以只需要找出一个就好了(ORZ)
                int x = *it;
                if(x <= r)
                    ++ans;
            }
            cout<<ans<<‘\n‘;        
        }
    }      
}

  垃圾如我,哭啦

codeforces打完补题

标签:problem   线段   ble   com   lower   std   一个   ORC   ios   

原文地址:https://www.cnblogs.com/newstartCY/p/11616651.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!