HDU 5057 Argestes and Sequence
描述
Argestes has a lot of hobbies and likes solving query problems especially. One day Argestes came up with such a problem. You are given a sequence a consisting of N nonnegative integers, a[1],a[2],…,a[n].Then there are M operation on the sequence.An operation can be one of the following:
S X Y: you should set the value of a[x] to y(in other words perform an assignment a[x]=y).
Q L R D P: among [L, R], L and R are the index of the sequence, how many numbers that the Dth digit of the numbers is P.
Note: The 1st digit of a number is the least significant digit.
输入格式
In the first line there is an integer T , indicates the number of test cases.
For each case, the first line contains two numbers N and M.The second line contains N integers, separated by space: a[1],a[2],…,a[n]—initial value of array elements.
Each of the next M lines begins with a character type.
If type==S,there will be two integers more in the line: X,Y.
If type==Q,there will be four integers more in the line: L R D P.
[Technical Specification]
1<=T<= 50
1<=N, M<=100000
0<=a[i]<=231 - 1
1<=X<=N
0<=Y<=231 - 1
1<=L<=R<=N
1<=D<=10
0<=P<=9
输出格式
For each operation Q, output a line contains the answer.
样例
输入
1
5 7
10 11 12 13 14
Q 1 5 2 1
Q 1 5 1 0
Q 1 5 1 1
Q 1 5 3 0
Q 1 5 3 1
S 1 100
Q 1 5 3 1
输出
5
1
1
5
0
1
思路
i,j表示最大不冲突字串的首和尾。
用26个队列来存26个字母的位置,当某个队列的size大于k时,明显冲突。计算i-j之间的子串的个数。要注意算重的部分,要减去。
i更新为对应队列里front的值。特别注意的是,位置在old_i和new_i之间的字母的队列要pop掉,这个BUG卡了我两个小时,OMG…………
代码很简约,也比较易懂。
思路
开一个1000001010(i,j,k)的树状数组。可以想到这个树状数组的意思是第i个数字的第j位是k的个数。
由于内存不够,顾用一个short和char来组合表示数字。short类型的最大整数是32767,所以%32768。
小技巧:
%*c
在输入和输出类似与这种表示方式的意思是跳过一个已经读取的或者即将要输出的字符。
c++代码
|
|