给定长度为 n 的 01 串 s=s1s2…sn,要求对每个位置 i,统计在它左侧(下标 <i)与 si 不同的字符个数。 我们可以采用前缀计数的方法:
定义两个变量 cnt0 和 cnt1,分别记录当前已遍历字符中 '0' 和 '1' 的个数。
对每个位置 i:
'1',即 ai=cnt1;牛牛拥有一个长度为n的01串s=“s1s2...sn”(下标从1开始)。
对于每个位置i(1≤i≤n),定义:
By signing up a CodeFun2000 universal account, you can submit code and join discussions in all online judging services provided by us.