无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

CF 1569A - Balanced Substring

2023-06-26 15:13 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a string s, consisting of n letters, each letter is either 'a' or 'b'. The letters in the string are numbered from 1 to n.

s[l;r] is a continuous substring of letters from index l to r of the string inclusive.

A string is called balanced if the number of letters 'a' in it is equal to the number of letters 'b'. For example, strings "baba" and "aabbab" are balanced and strings "aaab" and "b" are not.

Find any non-empty balanced substring s[l;r] of string s. Print its l and r (1≤l≤r≤n). If there is no such substring, then print ?1 ?1.

----------------------------------------

給定一個(gè)字符串 s,由 n 個(gè)字母組成,每個(gè)字母要么是“a”,要么是“b”。 字符串中的字母從 1 到 n 編號(hào)。

s[l;r] 是字符串中從索引 l 到 r 的連續(xù)字母子串。

如果字符串中字母“a”的數(shù)量等于字母“b”的數(shù)量,則該字符串被稱為平衡字符串。 例如,字符串“baba”和“aabbab”是平衡的,而字符串“aaab”和“b”則不是。

查找字符串 s 的任意非空平衡子串 s[l;r]。 打印它的 l 和 r (1≤l≤r≤n)。 如果不存在這樣的子串,則打印?1 ?1。

-----------------------------------------------

用presum來(lái)求和,然后依次去判斷即可;

下面是代碼:


CF 1569A - Balanced Substring的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
四川省| 河南省| 桐柏县| 木里| 宜兴市| 怀仁县| 徐闻县| 庄河市| 珲春市| 堆龙德庆县| 新竹县| 区。| 太和县| 亚东县| 志丹县| 土默特左旗| 汶川县| 霍邱县| 白银市| 仙桃市| 广东省| 咸宁市| 习水县| 开封市| 兴化市| 蒙自县| 阳新县| 来安县| 沾益县| 黄冈市| 田东县| 滁州市| 宿迁市| 教育| 临城县| 砚山县| 平乡县| 黄龙县| 东丽区| 桂平市| 分宜县|