• 2024-05-14LeetCode 1915. Number of Wonderful Substrings
    原题链接在这里:https://leetcode.com/problems/number-of-wonderful-substrings/description/题目:A wonderful stringisastringwhere atmostone letterappearsan odd numberoftimes.Forexample, "ccjjc" and "abab" arewonderful,but "ab&
  • 2024-05-05ABC240Ex Sequence of Substrings
    ABC240ExSequenceofSubstringsLIS的好题改编。约定\(S(l,r)\)为字符串\(s\)中第\(l\)位到底\(r\)​位。\(S(l,r)<S(x,y)\)为字符串中\([l,r]\)的子串字典序比\([x,y]\)的子串小。前置LIS的\(n\logn\)求法。题解我们考虑按照类似于朴素LIS的方式设状
  • 2024-03-22CF1930D1 - Sum over all Substrings (Easy Version)
    对于每一个\(f(i,j)\),我们考虑如何计算。我们发现,\(\texttt{1010}\)式的字符串很有用,所以这启发我们如果遇到了一个模式\(p_i=\texttt{'1'}\),那么我们可以在\(i+1\)的位置放一个\(\texttt{'1'}\)。这样我们直接处理了\(i,i+1,i+2\)。容易证明这是最优的。#incl
  • 2024-03-17UVA10829 L-Gap Substrings
    我永远喜欢数据结构。貌似是此题中第一个使用SA+分治+二维数点做法的题解?题目传送门给出字符串\(s\)和常数\(g\),求出有多少四元组\((l_1,r_1,l_2,r_2)\),满足\(s[l_1,r_1]=s[l_2,r_2]\)且\(r_1+g+1=l_2\)。\(T\)组数据,\(1\leT,g\le10\),\(|s|\le5\times10
  • 2024-02-21Go 100 mistakes - #41: Substrings and memory leaks
        WeneedtokeeptwothingsinmindwhileusingthesubstringoperationinGo. First,theintervalprovidedisbasedonthenumberofbytes,notthenumberofrunes. Second,asubstringoperationmayleadtoamemoryleakastheresultings
  • 2024-02-10CF316G3 Good Substrings
    题意简述有一个字符串\(s\)和\(n\)条限制,每条限制给出字符串\(t_i\)和两个整数\(l_i,r_i\),要求一个字符串要满足在\(t_i\)中的出现次数要在\([l_i,r_i]\)之间。求\(s\)有多少本质不同的子串满足所有限制。\(|s|,\max|t|\le5\times10^4,n\le10\)分析“本质不同
  • 2024-02-06ABC240Ex Sequence of Substrings
    题意简述有长度为\(n\)的01串,你现在要选出\(k\)个两两无交子串,使得将\(k\)个子串按照出现位置排序后,后者的字典序严格比前者大。最大化\(k\)。\(\bm{n\le2\times10^4}\)。分析首先的首先观察数据范围可知此题应该是个线性根号对数的时间复杂度首先有个显然的\(O(n
  • 2024-01-12python 串联所有单词的子串 多种解法
    解法一:使用递归deffind_substrings(s,words):ifnotsornotwords:return[]word_length=len(words[0])num_words=len(words)total_length=word_length*num_wordssubstrings=[]deffind_substrings_helper(s,
  • 2023-11-28Count Beautiful Substrings II
    CountBeautifulSubstringsIIYouaregivenastring s andapositiveinteger k.Let vowels and consonants bethenumberofvowelsandconsonantsinastring.Astringis beautiful if:vowels==consonants.(vowels*consonants)%k==0,inothert
  • 2023-10-12CF938F Erasing Substrings 题解
    ErasingSubstrings一个神奇的想法是设\(f_{i,j}\)表示在位置\([1,i]\)中,我们删去了长度为\(2^k(k\inj)\)的一些串,所能得到的最小字典序。使用二分加哈希可以做到\(O(n^2\log^2n)\),无法承受。发现对于状态\(f_{i,j}\),它已经确定了\(i-j\)位的串,因为所有\(\inj\)
  • 2023-09-15CF914F Substrings in a String
    知识点:bitset,SAM,根号分治Link:https://codeforces.com/problemset/problem/914/F一种在字符集较小情况下的多轮字符串匹配暴力的优化。好久没写过单题的题解了格式都忘了、、、简述给定一仅包含小写字母的字符串\(s\),给定\(q\)次操作,每次操作都是下列两种形式之一:将字符
  • 2023-07-05SPOJ Substrings 题解
    \(\text{SAM}\)入门好题。首先我们需要知道几个关于\(\text{SAM}\)的结论。结论1:题目中的\(f(x)\)单调下降。显然,对于长度为\(x\)的子串,其必存在一个\(x-1\)的后缀,这个后缀的\(\text{endpos}\)集合肯定包含子串的\(\text{endpos}\)集合,所以必有\(f(x-1)\le
  • 2023-05-26647. Palindromic Substrings刷题笔记
    用动态规划可以做,应该可以优化为只有两个表,而且不用每次res都加classSolution:defcountSubstrings(self,s:str)->int:n=len(s)dp=[[0]*nfor_inrange(n)]res=0foriinrange(n-1,-1,-1):forji
  • 2023-05-06Codeforces 1817F - Entangled Substrings(SA)
    为什么赛时不开串串题?为什么赛时不开串串题?为什么赛时不开串串题?为什么赛时不开串串题?为什么赛时不开串串题?一种SA做法,本质上和SAM做法等价,但是说来也丢人,一般要用到SAM的题我都是拿SA过的/wul考虑将\(ac\)看作一个整体。记\(\text{occ}(S)\)为\(S\)出现位置的集
  • 2023-04-28D. Unique Palindromes
    D.UniquePalindromesApalindromeisastringthatreadsthesamebackwardsasforwards.Forexample,thestringabcbaispalindrome,whilethestringabcaisnot.Let$p(t)$bethenumberofuniquepalindromicsubstringsofstring$t$,i.e.thenumber
  • 2023-04-13POJ 1226 Substrings (后缀数组)
    题目地址:POJ1226将每一个字符串反转连接一次,再把所有字符串都连接起来,然后二分,找最大长度。注意与反转字符串之间不能直接相连。代码如下:#include<iostream>#include<string.h>#include<math.h>#include<queue>#include<algorithm>#include<stdlib.h>#include<ma
  • 2023-04-13SPOJ 705 New Distinct Substrings (后缀数组)
    后缀数组模板题。由于height数组是指与排名上一个的公共前缀,所以重复的个数是height[i]个,考虑当前这个字母所构成的子串的贡献即为n-sa[i]-height[i],然后累加即可。代码如下:#include<iostream>#include<string.h>#include<math.h>#include<queue>#include<algorithm
  • 2023-03-19CF1801G A task for substrings
    题面传送门卡常的出题人什么时候似啊?如果\(l=1,r=|t|\),那么就是蠢得不能再蠢的问题:直接扔到AC自动机上跑匹配就好了,可以做到\(O(\sum|s|+|t|)\)。现在询问的变成了
  • 2023-03-12【题解】CF1801G A task for substrings
    考虑拆开贡献,前缀贡献痕容易算。而跨越\([l-1,l]\)的贡献,考虑在正串ACAM找到\([1,l-1]\),反串ACAM找到\([l,r]\),那么要做的就是在两串的fail链祖先上,找到能凑成完
  • 2023-03-08这个hash我也不会(Crazy Search )
    Manypeopleliketosolvehardpuzzlessomeofwhichmayleadthemtomadness.Onesuchpuzzlecouldbefindingahiddenprimenumberinagiventext.Such
  • 2023-02-20HDU 1238 Substrings
    SubstringsTimeLimit:2000/1000MS(Java/Others)    MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):7699    AcceptedSubmission(s):3474
  • 2023-02-04每日一道思维题——CF1691C - Sum of Substrings
    题意:给定一个长度为n的字符串算由SiSi+1构成的子字符串值如00为0,01为1,10为10,11为11F(s)为所有值之和求出此值的最小值思路:优先将1放到最后,其次将1放在开头其余的位置
  • 2023-01-24abc214 F - Substrings
    题意:求给定字符串\(s\)的不同非空子序列个数要求被选入的位置两两不相邻\(n\le2e5\)思路:如果没有不相邻的要求怎么做?\(f_i\)表示考虑\(s[1..i]\),并且选\(i\)
  • 2023-01-17CF1748B-Diverse Substrings
    长度为n的字符串,求出子串(只能从头尾依次删字符来得到子串)中,相同字符出现的最高次数小于等于不同字符的个数,这样的子串的个数以1~n个字符作为起点,枚举终点的位置来判断每种
  • 2023-01-11[LeetCode] 2272. Substring With Largest Variance
    Thevarianceofastringisdefinedasthelargestdifferencebetweenthenumberofoccurrencesofany2characterspresentinthestring.Notethetwochara