题目链接: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. DOM中获取元素的节点兼容IE6-8封装,带jquery源码分析children

    <ul id="box"> <li>第一个节点</li> <li>第二个节点</li> <li>第三个节点& ...

  2. PhpStorm+XAMPP+Xdebug 集成开发和断点调试环境配置

    0x01 Xdebug安装 参考:https://xdebug.org/docs/install cd xdebug-/ phpize sudo ./configure --enable-xdebug ...

  3. Java ServerSocket详解

    ServerSocket 构造方法 ServerSocket serverSocket = new ServerSocket(); ServerSocket(); //无参数 ServerSocket ...

  4. 动态规划-Minimum Insertion Steps to Make a String Palindrome

    2020-01-05 11:52:40 问题描述: 问题求解: 好像多次碰到类似的lcs的变种题了,都是套上了回文的壳.这里再次记录一下. 其实本质就是裸的lcs,就出结果了. public int ...

  5. 搭建生产级的Netty项目

    Netty是Trustin Lee在2004年开发的一款高性能的网络应用程序框架.相比于JDK自带的NIO,Netty做了相当多的增强,且隔离了jdk nio的实现细节,API也比较友好,还支持流量整 ...

  6. OpenCV-Python | 图像的基本操作 十

    目标 学会: 访问像素值并修改它们 访问图像属性 设置感兴趣区域(ROI) 分割和合并图像 本节中的几乎所有操作都主要与Numpy相关,而不是与OpenCV相关.要使用OpenCV编写更好的优化代码, ...

  7. 使用electron和node-serialport的环境搭建过程

    项目运行所需环境 1,必须安装nodejs 附上node下载地址-Nodejs node安装过程简单, 一直next就行了,我安装的版本是12.16.1,可以在powershell中通过 node - ...

  8. Linux上的软件安装有哪些方式?

    Linux上的软件安装有以下几种常见方式介绍 1.二进制发布包 软件已经针对具体平台编译打包发布,只要解压,修改配置即可 2.RPM包 软件已经按照redhat的包管理工具规范RPM进行打包发布,需要 ...

  9. MATLAB GUI设计(3)

    一.gca.gcf.gco 1.三者的功能定义: gcf 返回当前Figure 对象的句柄值 gca 返回当前axes 对象的句柄值 gco 返回当前鼠标单击的句柄值,该对象可以是除root 对象外的 ...

  10. Javascript/Jquery遇到字符串自动NaN的问题

    结果发现是一个id绑定了两次点击事件.修改之后,问题解决.