#P8132. [ICPC2020 WF] Landscape Generator

[ICPC2020 WF] Landscape Generator

题目背景

ICPC2020 WF E

题目描述

Interactive Creative Players Collective (ICPC) is working on a new computer game for which they want to generate realistic landscapes. One of the ICPC engineers proposed an algorithm inspired by geological processes. The algorithm starts with a flat landscape and repeatedly modifies it by lifting or lowering continuous blocks, thus forming horsts (lifted blocks) and grabens (lowered blocks). The blocks to be lifted or lowered are selected at random. ICPC hopes to obtain realistic landscapes this way.

Your task is to interpret any sequence of such modifications and output the resulting landscape. The landscape is represented by a sequence of nn integer height values, one for each integer point from 11 to nn on the xx-axis. Figure E.1 illustrates an example by connecting the height values with line segments.

Initially the height is 00 at all nn points. This flat shape is subjected to a sequence of modifications. Each modification applies one of the following four operations with two integer parameters x1x2x_1 \leq x_2:

  • R\texttt{R}: Raise -- increase the height by 11 at all points between x1x_1 and x2x_2 inclusive.
  • D\texttt{D}: Depress -- decrease the height by 11 at all points between x1x_1 and x2x_2 inclusive.
  • H\texttt{H}: Hill -- add a new linearly shaped hill between x1x_1 and x2x_2.
  • V\texttt{V}: Valley -- add a new linearly shaped valley between x1x_1 and x2x_2.

Adding a hill to the current landscape works as follows. The heights at points x1x_1 and x2x_2 are increased by 11. If x2x1>1x_2 - x_1 > 1, the heights at points x1+1x_1 + 1 and x21x_2 - 1 are increased by 22. If x2x1>3x_2 - x_1 > 3, the heights at points x1+2x_1 + 2 and x22x_2 - 2 are increased by 33, and so on. Figure E.2 shows an example. Adding a valley works in the same way except the heights are decreased instead. The maximal change of height happens in the middle between x1x_1 and x2x_2. If x2x1x_2 - x_1 is odd, there will be two neighboring points with maximal change, otherwise just one.

输入格式

The first line of input contains two integers nn and kk, where nn (1n2000001 \leq n \leq 200\,000) is the number of points, and kk (0k2000000 \leq k \leq 200\,000) is the number of modifications. The nn points along the xx-axis are numbered from 11 to nn. The next kk lines describe the modifications. Each line contains one character cc and two integers x1x_1 and x2x_2, where cc (one of R\texttt{R}, D\texttt{D}, H\texttt{H} or V\texttt{V}) designates the operation and x1x_1 and x2x_2 (1x1x2n1 \leq x_1 \leq x_2 \leq n) specify its parameters.

输出格式

Output nn lines, where the ithi^{\text{th}} line contains the height at point ii after applying all modifications in the given order.

题目大意

题目背景

ICPC2020 WF E

题目描述

Interactive Creative Players Collective (ICPC)正在创作一款游戏,他们想为它生成真实的地形。一位ICPC工程师受地质过程启发,提出了一种算法,该算法从一个平地开始,重复地通过上升或下降一些连续的区块来改变地形,这样就会形成地垒(即上升的区块)和地堑(即下降的区块)。上升或下降的区块是随机选择的。ICPC希望通过这种方法获得真实的地形。

你的任务是根据所有的更改地形指令输出得到的地形,地形可表示为一个由nn个整数组成的数组,每个整数代表xx轴上的点11nn的海拔高度值。图表E.1是将这些值用折线连接起来的一个例子。

图表E.1:由样例输入#1生成的地形

最初,这nn个点的海拔都是0,接下来这个图形会受到一系列的修改,每条修改指令是以下四条之一,并且有两个参数x1x2x_1 \le x_2

  • R\texttt{R}: Raise(上升)——将x1x_1x2x_2的所有点的海拔均增加11
  • D\texttt{D}: Depress(下降)——将x1x_1x2x_2的所有点的海拔均减少11
  • H\texttt{H}: Hill(山丘)——在x1x_1x2x_2之间形成一座“山丘”。
  • V\texttt{V}: Valley(峡谷)——在x1x_1x2x_2之间形成一条“峡谷”。

向现有地形添加一座“山丘”的原理如下:点x1x_1x2x_2的海拔增加1;如果x2x1>1x_2-x_1>1,那么点x1+1x_1+1x21x_2-1的海拔增加2;如果x2x1>3x_2-x_1>3,那么点x1+2x_1+2x22x_2-2的海拔增加3;以此类推。图表E.2是一个例子。添加一条“峡谷”与上述原理相同,只是海拔是减少而非增加。海拔改变最大的点在x1x_1x2x_2的中间,如果x2x1x_2-x_1是偶数,就会有两个相邻的点海拔改变最大,否则只有一个点。

图表E.2:样例输入#2生成的地形

输入格式

输入的第一行包含两个整数nnkk,其中nn (1n2×1051 \le n \le 2\times10^5)代表点的数量,kk (0k2×1050 \le k \le 2\times10^5)代表修改指令的数量。xx轴上的nn个点被编号为11nn

接下来的kk行描述修改。每行包含一个字符cc和两个整数x1x_1x2x_2,其中cc (为R\texttt{R}, D\texttt{D}, H\texttt{H}, V\texttt{V}之一)代表操作种类,x1x_1x2x_2 (1x1x2n1 \le x_1 \le x_2 \le n)是具体参数。

输出格式

输出共nn行,其中第ii行为所有修改完成后点ii的海拔。

20 13
H 12 13
D 5 18
R 13 14
R 8 16
H 2 3
V 10 19
V 3 13
R 8 13
V 3 10
D 5 18
V 11 12
R 1 6
R 14 19
1
2
0
-3
-7
-9
-11
-9
-7
-6
-6
-5
-3
-4
-5
-4
-4
-3
0
0
7 1
H 1 6
1
2
3
3
2
1
0