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‘; } } }
垃圾如我,哭啦
原文地址:https://www.cnblogs.com/newstartCY/p/11616651.html
时间: 2024-10-12 22:15:39