div3--D - Distinct Characters Queries
题目链接:https://codeforces.com/contest/1234/problem/D
题目大意:
对于给定的字符串,给出n个查询,查询时输入3个数啊,a,b,c,如果说a==1,则将位置b上的元素变为c,如果数a==2,则输出b到c之间有多少种字母;
这个题目写了好久,正解好像是用树状数组(第一次听说)。 不过还可以用set来写;
用set开的二维数组,也是从小到大排序好的,更骚的操作是可以直接用erase即想要删除a只要s.erase(a)就可以了。
set还支持二分查找,找到的返回地址,找不到返回的是end。。。。。
AC代码:
#include<bits/stdc++.h>
using namespace std;
set<int >se[];
set<int >::iterator it;
char s[+];
void solve(){
cin>>s+;
int x=strlen(s+);
for(int i=;i<=x;i++){
se[s[i]-'a'].insert(i);
}
int n;
cin>>n;
while(n--){
int t;
cin>>t;
if(t==){
int a;
char x;
cin>>a>>x;
se[s[a]-'a'].erase(a);
se[x-'a'].insert(a);
s[a]=x;
}
else {
int sum=;
int l,r;
cin>>l>>r;
for(int i=;i<;i++){
it=se[i].lower_bound(l);
if(it!=se[i].end() && *it<=r) sum++;
}
cout<<sum<<endl;
}
}
} int main(){
ios::sync_with_stdio(false);
solve();
return ;
}
div3--D - Distinct Characters Queries的更多相关文章
- Codeforces Round #590 (Div. 3) D. Distinct Characters Queries(线段树, 位运算)
链接: https://codeforces.com/contest/1234/problem/D 题意: You are given a string s consisting of lowerca ...
- Codeforces Round #590 D. Distinct Characters Queries
CF上给的标签是数据结构.但给的题解里的方法是很巧的暴力,用vector<set>维护每个字母出现的下标,每次修改加下标,擦下标.每次询问对每个字母分别lower_bound查找区间内是否 ...
- [LeetCode] Longest Substring with At Most K Distinct Characters 最多有K个不同字符的最长子串
Given a string, find the length of the longest substring T that contains at most k distinct characte ...
- [LeetCode] Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串
Given a string S, find the length of the longest substring T that contains at most two distinct char ...
- Leetcode: Longest Substring with At Most K Distinct Characters && Summary: Window做法两种思路总结
Given a string, find the length of the longest substring T that contains at most k distinct characte ...
- ✡ leetcode 159. Longest Substring with At Most Two Distinct Characters 求两个字母组成的最大子串长度 --------- java
Given a string, find the length of the longest substring T that contains at most 2 distinct characte ...
- LeetCode Longest Substring with At Most Two Distinct Characters
原题链接在这里:https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters/ 题目: Gi ...
- LeetCode "Longest Substring with At Most K Distinct Characters"
A simple variation to "Longest Substring with At Most Two Distinct Characters". A typical ...
- [Locked] Longest Substring with At Most Two Distinct Characters
Longest Substring with At Most Two Distinct Characters Given a string, find the length of the longes ...
随机推荐
- Contest 154
2019-09-16 17:22:28 总体感受:这次比赛的模版题也太多了吧,两条模版题没有想出来.总的来说,还是自己的刷题量还是严重的不够. 注意点: 1)提升刷题量和覆盖率非常重要: 2)在碰到大 ...
- [BFS]Codeforces Igor In the Museum
Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standard ...
- IDEA编写 Scala时没有语法检查和错误提示
#问题描述 在IDEA中写scala程序时,一些明显的语法错误不进行检查,没有像写Java时的红线什么的,当编译运行时,编译失败. https://blog.csdn.net/weizheng1000 ...
- HDU - 1160 最长上升子序列以及记录路径
题意:第一列,给出老鼠的重量,第二列,给出老鼠的速度,要证明老鼠的重量越大,速度越小,给出最多老鼠的数量,并说明第几只. 思路:先将老鼠按照重量从大到小排序,然后速度是从小到大,求最长上升子序列,学习 ...
- kaggle入门——泰坦尼克之灾
目录 引言 数据认识 总结 特征处理 建模预测 logistic分类模型 随机森林 SVM xgboost 模型验证 交叉验证 学习曲线 高偏差: 高方差 模型融合 总结 后记 引言 一直久闻kagg ...
- MATLAB GUI设计(3)
一.gca.gcf.gco 1.三者的功能定义: gcf 返回当前Figure 对象的句柄值 gca 返回当前axes 对象的句柄值 gco 返回当前鼠标单击的句柄值,该对象可以是除root 对象外的 ...
- 通过pycharm使用git和github的步骤(图文详解)
一.在Pycharm工具中配置集成Git和GitHub.1.集成Git. 打开Pycharm, 点击File-->Settins-->Version Control-->Git 然 ...
- 玩转控件:封装Dev的SearchLookupEdit
鸣谢 随着前面几个章节对控件封装与扩展的分享,不少小伙伴儿们在作者公众号上反馈,并联系作者,表示通过这些系列和源码能学到不少细节上的东西,并运用到了自己的实际项目当中,也有不少伙伴儿反馈更好更优的处理 ...
- mysql 中UNIQUE KEY 到底是约束还是索引?
答案来自:https://zhidao.baidu.com/question/1863373387452612907.html 两者关系 unique索引包含了unique约束,因为unique约束是 ...
- Golang入门(4):并发
摘要 并发程序指同时进行多个任务的程序,随着硬件的发展,并发程序变得越来越重要.Web服务器会一次处理成千上万的请求,这也是并发的必要性之一.Golang的并发控制比起Java来说,简单了不少.在Go ...