题目链接: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. Convert JS object to JSON string

    Modern browsers (IE8, FF3, Chrome etc.) have native JSON support built in (Same API as with JSON2). ...

  2. C++实现秒表

    完整代码下载 思路概括:如果有键按下,判断按下的是什么键并处理.没有键按下,计时.传统的Sleep无法满足秒表精确到百毫秒的需求,这里使用更精确的clock,clock的作用是统计从程序开始运行到现在 ...

  3. 【译】Java SE 14 Hotspot 虚拟机垃圾回收调优指南

    原文链接:HotSpot Virtual Machine Garbage Collection Tuning Guide,基于Java SE 14. 本文主要包括以下内容: 优化目标与策略(Ergon ...

  4. Python Tkinter Grid布局管理器详解

    Grid(网格)布局管理器会将控件放置到一个二维的表格里.主控件被分割成一系列的行和列,表格中的每个单元(cell)都可以放置一个控件. 注意:不要试图在一个主窗口中混合使用pack和grid (1) ...

  5. MATLAB——文件读写(2)

    一.importdata函数 1. txt 如图,提取经纬度. 程序如下 clear all test=importdata('经纬度.txt'); [r,c]=size(test.data);%ro ...

  6. Oracle ROWNUM用法

    很多朋友应该跟我一样有个疑问,为什么rownum > 5 的时候会查不到一条数据,用rownum < 5就可以查到数据,明明查询所有的时候rownum有很多啊,小朋友,你是不是有很多问号? ...

  7. python编程心得(1)

    1.创建字典     字典名 = {键名1:键值1,键名2:键值2,...}     sanguo = {"诸葛亮草船借箭":"满载而归","关公赴会 ...

  8. AJAX对数据库增删改查实例

    前端代码: <!DOCTYPE html><html><head><meta charset="UTF-8"><title&g ...

  9. 使用Homebrew在Mountain Lion上安装MySQL

    一.安装mysql brew install mysql 二.开机启动mysql brew info mysql 根据提示,设置开机启动 三.设置mysql开启和停止命令 alias mysql-st ...

  10. 来,让我们一起来学习VIM

    什么是VIM vim是一个高度可定制的文本编辑器,被很多专业的程序员使用,并获得了程序员的一致好评. 下图是Vim的官网vim.org 你可以在Vim的官网免费下载并使用Vim,同样可以在Vim官网学 ...