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 ...
随机推荐
- java-Deque
2020-03-07 13:42:05 双端队列与通常的Queue的区别仅仅在于多了双端队列可以在队首队尾进行插入或者删除操作. 队尾添加:offerLast 队尾删除:pollLast 队尾查询:p ...
- codeforces 1236 A. Bad Ugly Numbers
A. Bad Ugly Numbers time limit per test 1 second memory limit per test 256 megabytes input standard ...
- vim-0-indent(缩进)
缩进: 参考自http://liuzhijun.iteye.com/blog/1831548,http://blog.csdn.net/chenxiang6891/article/details/41 ...
- js实现动态球球背景
document.getElementsByTagName("body")[0].style.backgroundColor="#000" //构造函数 fun ...
- 深度学习框架Keras与Pytorch对比
对于许多科学家.工程师和开发人员来说,TensorFlow是他们的第一个深度学习框架.TensorFlow 1.0于2017年2月发布,可以说,它对用户不太友好. 在过去的几年里,两个主要的深度学习库 ...
- Nature重磅:华裔科学家成功解码脑电波,AI直接从大脑中合成语音
[导读]Nature发表华裔作者论文:通过解码大脑活动提升语音的清晰度,使用深度学习方法直接从大脑信号中产生口语句子,达到150个单词,接近正常人水平. 大脑活动能够解码成语音了. 说话似乎是一项毫不 ...
- XCode8 安装模拟器
1.下载模拟器 参考:http://blog.csdn.net/piratest/article/details/52538978 参考:http://blog.csdn.net/zhangao008 ...
- mongodb服务器启动
以配置文件启动服务器: mongod --config /usr/local/mongodata/config/mongodb.conf(配置文件路径) 客户端启动: mango 关闭mongodb的 ...
- Matlab GUI设计(2)
11. (1)界面设计 (2)添加按钮的回调函数 function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle ...
- Java实现3次找到假球
前言 之前老师让写一个程序,就写了写. 正文 题目要求 程序要求 10个铅球中有一个假球(比其他铅球的重量要轻),用天平三次称出假球. 程序设计思路 第一次使用天平分别称5个球,判断轻的一边有假球:拿 ...