~{→看不见LaTex格式的Dalao们请刷新本页Thanks♪(・ω・)ノ←}~
The Trip On Abandoned Railway
题面
There are many ghosts at the abandoned station on unknown railway.
We mark the abandoned stations as $1,2..n$ according to the order. There are $a_i$ ghosts at the $i^{th}$ station.Yakumo Yukari often opens a black hole and makes a train appearing at a certain station. For example, the train appears at the $x$ station, and $k$ ghosts get off at the station. Then there would be $k+d$ ghosts at the $x+1$ station to get off,$k+2×d$ at $x+2$ station and so on….There would be $k+y∗d$ ghosts at the $x+y$ station to get off ($0≤y,x+y≤n$). In others words, the numbers getting off at $x,x+1,x+2..n$ station form a tolerance of $d$ arithmetic progression.(you can consider ghosts getting off at the same time.)Onozuka Komachi would comes a certain station to take away the ghosts.(The number of ghosts at the station would become $0$)You have the records of trains appearing and Komachi coming. You should tell Komachi how much ghosts at a certain station when she come to there.
简要翻译
一开始给定一个序列$a_i$,你要进行两种操作。
- 从第$x$个位置到第$n$个位置,分别加上$y,y+d,y+2×d,y+3×d…$的一个等差数列。
- 询问第$x$个位置的数,并且将该位置清零。
Input
第一行包含一个整数$T$,表示测试数据的组数。
每组数据第一行包含三个整数$n$,$m$,$d$,其中$n$表示序列长度,$m$表示操作个数,$d$表示等差数列的公差。第二行包含$n$个整数,表示$a_i$。下面包含$m$行,每行开头一个整数$1/2$,表示操作类型。
- 如果是$1$,则下面有两个整数$x$,$y$如题意。
- 如果是$2$,则下面包含一个整数$x$表示要查询的位置。
Output
对于每个$2$操作,输出一个整数表示答案。
Sample Input
2
6 6 1
1 2 3 3 2 1
1 1 1
2 1
2 2
2 3
2 4
2 5
5 3 2
1 2 3 4 5
1 3 0
2 4
2 4
Simple Output
2
4
6
7
7
6
0
Hint
$1\le T\le 10$。
$1\le n\le 10^5$,$1\le m\le 10^5$,$1\le d\le 10^3$。
$1\le a_i\le 10^3$,$1\le x\le n$,$0\le y\le 10^3$。
样例说明
说明每一次操作后的序列:
1 | case1: |
1 | case2: |
emmmmm,之前做过一道题,所以这题切起来比较轻松。
加上等差数列,我们明显就可以知道,等差数列每一项之差就是$d$,所以我们只要将$x+1$~$n$的位置都加上$d$,用线段树修改区间,在$x$的位置上用树状数组单点修改。查询时,求出线段树上$x$的前缀表示修改的总和,加上树状数组$x$位置的值和原本该位置上的值,求和即可。对于清空操作,也只要对这位减掉查询出来的值即可。
Code
说起来容易,但是,我只想说,这题的代码真的有毒,中间取模你的答案就错了,中间不能取模,也不会爆掉long long。
1 |
|