【题目来源】
http://acm.hdu.edu.cn/showproblem.php?pid=5057
【题目描述】
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.
Argestes有很多爱好,尤其喜欢解决查询问题。
有一天,Argestes 提出了这样一个问题。给定一个由 N 个非负整数 a[1],a[2],…,a[N] 组成的序列。序列上有 M 个操作:
S X Y:将 a[X] 的值设置为 Y,即 a[X]=Y。
Q L R D P:在 [L, R] 中,查询有多少个数的第 D 位是 P。注:数字的第 1 位是最低有效位。
【输入格式】
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.
在第一行有一个整数 T,表示测试用例的数量。
对于每个测试,第一行包含两个数字 N 和 M,第二行包含 N个整数,用空格分开。接下来的 M 行,每行代表一种操作。
S X Y:将 a[X] 的值设置为 Y,即 a[X]=Y。
Q L R D P:在 [L, R] 中,查询有多少个数的第 D 位是 P。
【输出格式】
For each operation Q, output a line contains the answer.
对于每个操作Q,输出一行答案。
【输入样例】
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
【数据范围】
1<=T<= 50
1<=N, M<=100000
0<=a[i]<=23^1-1
1<=X<=N
0<=Y<=23^1-1
1<=L<=R<=N
1<=D<=10
0<=P<=9
【算法分析】
● 本题其实就是线段树“