题目链接: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的更多相关文章

  1. 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 ...

  2. Codeforces Round #590 D. Distinct Characters Queries

    CF上给的标签是数据结构.但给的题解里的方法是很巧的暴力,用vector<set>维护每个字母出现的下标,每次修改加下标,擦下标.每次询问对每个字母分别lower_bound查找区间内是否 ...

  3. [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 ...

  4. [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 ...

  5. 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 ...

  6. ✡ 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 ...

  7. LeetCode Longest Substring with At Most Two Distinct Characters

    原题链接在这里:https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters/ 题目: Gi ...

  8. LeetCode "Longest Substring with At Most K Distinct Characters"

    A simple variation to "Longest Substring with At Most Two Distinct Characters". A typical ...

  9. [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 ...

随机推荐

  1. 数据库-Mysql语句

    Mysql语句 不定时更新 1.数据库相关的语句 /* 数据库操作 */ ------------------ -- 启动MySQL net start mysql -- 接与断开服务器 mysql ...

  2. 动态规划-Minimum Cost to Merge Stones

    2019-07-07 15:48:46 问题描述: 问题求解: 最初看到这个问题的时候第一反应就是这个题目和打破气球的题目很类似. 但是我尝试了使用dp将问题直接转为直接合并到一个堆问题复杂度迅速提高 ...

  3. PMP备考日记(一)

    本人在今年1月份就开始有考PMP证的一个想法,结果头脑一热就报名了.本来计划今年3月份就要进行PMP考试,一直都在备考中,结果谁知道来了新冠状病毒,彻底打乱了自己的脚步.PMI也将PMP考试延迟到了今 ...

  4. 文献名:Repeat-Preserving Decoy Database for False Discovery Rate Estimation in Peptide Identication (用于肽段鉴定中错误发生率估计的能体现重复性的诱饵数据库)

    文献名:Repeat-Preserving Decoy Database for False Discovery Rate Estimation in Peptide Identication (用于 ...

  5. 什么是CPU load

    最近经常收到告警,CPU load大于阈值告警.查看系统的CPU是12核,告警阈值设置的是8.对于CPU load一直有个模糊的概念,具体是什么意思还真搞不明白,趁这个机会好好搞搞究竟. 1.查看CP ...

  6. Unix 网络编程卷一源码编译踩坑记录 ubtutu 19.10

    在阅读unpv1时运行源代码的环境配置,这里简单记录一下 源代码里的README 写得挺详细的,但是在Linux 系统的下还没没办法直接编译通过的, 这里我使用的是ubuntu 19.10(在腾讯云1 ...

  7. iOS 优化实例

    一.接口请求优化 在工程项目中,多个一级界面包含状态,如:服务入口的动态配置,未读消息数量,图片文字等,因此产品设计要每次切换 tab 时都请求数据,及时的更新页面状态.在实际开发中,频繁的调用接口, ...

  8. 艾编程coding老师课堂笔记:java设计模式与并发编程笔记

    设计模式概念 1.1 什么是设计模式 设计模式(Design Pattern)是前辈们对代码开发经验的总结,是解决特定问题的一系列套路.它不是语法规定,而是一套用来提高代码可复用性.可维护性.可读性. ...

  9. Pointer Lock API(3/3):一个Demo

    简单的Demo演练 点击跳转至Code Pen以查看演示和源码 完整代码 <!DOCTYPE HTML> <html lang="en-US"> <h ...

  10. 201771010108 -韩腊梅-java学习进度表

    2018面向对象程序设计(Java)课程进度表 周次 (阅读/编写)代码行数  发布博文量/评论他人博文数量  课余学习时间(小时)  学习收获最大的程序阅读或编程任务 1 30/40 1/0 8   ...