div3--D - Distinct Characters Queries】的更多相关文章

链接: https://codeforces.com/contest/1234/problem/D 题意: You are given a string s consisting of lowercase Latin letters and q queries for this string. Recall that the substring s[l;r] of the string s is the string slsl+1-sr. For example, the substrings…
CF上给的标签是数据结构.但给的题解里的方法是很巧的暴力,用vector<set>维护每个字母出现的下标,每次修改加下标,擦下标.每次询问对每个字母分别lower_bound查找区间内是否存在这样位置,实在太妙了! 先看题解的方法. #include <bits/stdc++.h> #define debug(x) cout << #x << ": " << x << endl using namespace st…
题目链接: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还支持二分查找,找到…
Given a string, find the length of the longest substring T that contains at most k distinct characters. For example, Given s = “eceba” and k = 2, T is "ece" which its length is 3. 这道题是之前那道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 characters.For example,Given S = “eceba”,T is “ece” which its length is 3. 这道题给我们一个字符串,让我们求最多有两个不同字符的最长子串.那么我们首先想到的是用哈希表来做,哈希表记录每个字符的出现次数,然后如果哈希表中的映射数量超过两…
Given a string, find the length of the longest substring T that contains at most k distinct characters. For example, Given s = "eceba" and k = 2, T is "ece" which its length is 3. 我的做法:维护一个window,r移动到超出k distinct character限制是更新max,然后移动…
Given a string, find the length of the longest substring T that contains at most 2 distinct characters. For example, Given s = "eceba", T is "ece" which its length is 3. 给一个字符串,求这个字符串中,由两个字母组成的,连续的最长子串的长度. 虽然是hard,但是感觉并没有什么难度. 用ch1和pre…
原题链接在这里:https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters/ 题目: Given a string, find the length of the longest substring T that contains at most 2 distinct characters. For example, Given s = “eceba”, T is "ece"…
A simple variation to "Longest Substring with At Most Two Distinct Characters". A typical sliding window problem. class Solution { public: int lengthOfLongestSubstringKDistinct(string s, int k) { unordered_map<char, unsigned> hm; , start =…
Longest Substring with At Most Two Distinct Characters Given a string, find the length of the longest substring T that contains at most 2 distinct characters. For example, Given s = “eceba”, T is "ece" which its length is 3. 分析: 最多包含两个不同字母的子串,至少…