Doom HDU - 5239(线段树+思维)
THE END IS COMINGGGGGG!
Mike has got stuck on a mystery machine. If he cannot solve this problem, he will go to his doom.
This machine is consist of n cells, and a screen. The i-th cell contains a number ai(1≤i≤n). The screen also contains a number s, which is initially 0.
There is a button on each cell. When the i-th is pushed, Mike observes that, the number on the screen will be changed to s+ai, where s is the original number. and the number on the i-th cell will be changed to a2i.
Mike observes that the number is stored in radix p, where p=9223372034707292160. In other words , the operation is under modulo p.
And now, Mike has got a list of operations. One operation is to push buttons between from l-th to r-th (both included), and record the number on the screen. He is tired of this stupid work, so he asks for your help. Can you tell him, what are the numbers recorded.
Input
The first line contains an integer T(T≤5), denoting the number of test cases.
For each test case, the first line contains two integers n,m(1≤n,m≤105).
The next line contains n integers ai(0≤ai<p), which means the initial values of the n cells.
The next m lines describe operations. In each line, there are two integers l,r(1≤l≤r≤n), representing the operation.
Output
For each test case, output ‘‘Case #t:’’, to represent this is the t-th case. And then output the answer for each query operation, one answer in a line.
For more details you can take a look at the example.
Sample Input
2
4 4
2 3 4 5
1 2
2 3
3 4
1 4
1 3
2
1 1
1 1
1 1
Sample Output
Case #1:
5
18
39
405
Case #2:
2
6
22
給出n個數和m個操作,每個操作給出l和r,求出l到r的和來后,就把l到r之間的數都平方。每次輸出的結果都加上之前的結果。。
打表找規律,不斷模上那個數之后將近三十次之后,就不會變了。這樣就不會一直更新。設一個flag標記一下就行。注意要用unsigned long long,并且在平方的時候注意用快速乘。
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Doom HDU - 5239(线段树+思维)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Codeforces Round #57
- 下一篇: 权值线段树小结(hdu多校,普通平衡树,