码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5057 Argestes and Sequence(分块算法)

时间:2014-10-02 02:29:22      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   os   ar   java   

Argestes and Sequence

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 566    Accepted Submission(s): 142

Problem Description

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.

Input

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]<=$2^{31}$ - 1
1<=X<=N
0<=Y<=$2^{31}$ - 1
1<=L<=R<=N
1<=D<=10
0<=P<=9

Output

For each operation Q, output a line contains the answer.

Sample Input

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

Sample Output

5 1 1 5 0 1

 

分块算法:大致就是把一堆(包含n个基本单位)东西分成sqrt(n)块, 每块包含sqrt(n)个基本单位。

如果要修改某个基本单位,只要修改该单位所在的块,因为每块包含sqrt(n)个基本单位,所以时间复杂度为sqrt(n);

bubuko.com,布布扣view code

 

hdu 5057 Argestes and Sequence(分块算法)

标签:des   style   blog   http   color   io   os   ar   java   

原文地址:http://www.cnblogs.com/zyx1314/p/4003684.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!