#P15589. [KTSC 2026] 瞭望塔 / Observation Tower

    ID: 17551 远端评测题 6000ms 2048MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>交互题2026KTSC(韩国)

[KTSC 2026] 瞭望塔 / Observation Tower

Problem Description

There are NN observation towers, numbered 0∼N−10\sim N-1 in order. The height of tower ii is H[i]H[i], and its observation score is S[i]S[i]. Initially, S[i]=0S[i]=0.

For 0≤i<j≤N−10\le i\lt j\le N-1, we say that tower jj can be observed from tower ii if and only if for any i≤k≤j−1i\le k\le j-1, we have H[k]<H[j]H[k]\lt H[j]. Note that when j≤ij\le i, tower jj cannot be observed from tower ii.

When an observation operation is performed on some tower, the observation scores of all towers that can be observed from this tower will each increase by 11.

Now there are QQ events, and each event is one of the following three types:

  • Observe: given II (0≤I≤N−20\le I\le N-2), perform one observation operation on tower II.
  • Query: given L,RL,R (0≤L≤R≤N−10\le L\le R\le N-1), compute S[L]+⋯+S[R]S[L]+\cdots+S[R].
  • Shift: given L,R,VL,R,V (0≤L≤R≤N−10\le L\le R\le N-1). For any L≤i≤RL\le i\le R, set H[i]←H[i]+VH[i]\gets H[i]+V.

An observe event is represented by an array [I][I]; a query event is represented by an array [L,R][L,R]; a shift event is represented by an array [L,R,V][L,R,V]. Note that the array sizes of these three types of events are all different, so the event type can be distinguished by the array size.

Events occur in order 0∼Q−10\sim Q-1, and event ii is denoted by E[i]E[i].

Let the total number of query events be KK, numbered 0∼K−10\sim K-1 in the order they occur. Output the results of all query events.

Implementation Details

This is a function-style interactive problem. You do not need to, and should not, implement the main function.

You should implement the following function:

vector<long long> tower_events(vector<int> H, vector<vector<int>> E)
  • HH: an integer array of length NN.
  • EE: an integer array of length QQ, representing the events.
  • Return an integer array XX of length KK, where X[i]X[i] is the result of the ii-th query event.
  • This function is called exactly once.

Input Format

The input format of the sample grader is as follows:

  • Line 11: NN QQ.
  • Line 22: H[0]H[0] H[1]…H[N−1]H[1] \dots H[N - 1].
  • For all 0≤i≤Q−10 \le i \le Q - 1:
    • Line 3+i3 + i: ∣E[i]∣|E[i]| E[i][0]…E[i][∣E[i]∣−1]E[i][0] \dots E[i][|E[i]| - 1].

Output Format

The sample grader outputs the answers in the following format:

  • For all 0≤i≤K−10 \le i \le K - 1:
    • Line 1+i1 + i: X[i]X[i].
5 5
1 2 3 4 5
1 0
2 1 3
3 1 2 1
1 1
2 0 4

3
6

10 11
7 7 9 5 8 10 2 9 2 2
1 1
3 6 8 6
1 1
2 1 9
1 3
1 8
2 2 4
1 5
3 1 1 7
1 1
2 0 9

5
3
10

Hint

Constraints

  • 5≤N≤1 000 0005\le N\le 1\, 000\, 000.
  • 1≤Q≤250 0001\le Q\le 250\, 000.
  • 1≤H[i]≤1091\le H[i]\le 10^9.
  • For observe events, 0≤I≤N−20\le I\le N-2.
  • For query events, 0≤L≤R≤N−10\le L\le R\le N-1.
  • For shift events, 0≤L≤R≤N−10\le L\le R\le N-1, −109≤V≤109-10^9\le V\le 10^9.
  • After a shift event occurs, it is guaranteed that H[i]≥1H[i]\ge 1.
  • There is at least one query event.

Subtasks

ID Score Constraints
11 1717 N,Q≤150 000N,Q\le 150\, 000; in all query events, L=0,R=N−1L=0,R=N-1
22 6 6 N,Q≤150 000N,Q\le 150\, 000; no shift events
33 1212 N,Q≤150 000N,Q\le 150\, 000
44 1919 in all observe events, I=0I=0; in all shift events, L=RL=R; shift events occur at most 30 00030\, 000 times
55 2121 in all query events, L=RL=R; in all shift events, L=RL=R and V≥0V\ge 0
66 2525 no additional constraints

Samples

Sample 11

Consider the following call:

tower_events([1, 2, 3, 4, 5], [[0], [1, 3], [1, 2, 1], [1], [0, 4]])
  • After the first event, H=[1,2,3,4,5]H = [1, 2, 3, 4, 5], S=[0,1,1,1,1]S = [0, 1, 1, 1, 1].
  • The result of the second event (i.e., query event 00) is S[1]+S[2]+S[3]=3S[1] + S[2] + S[3] = 3.
  • After the third event, H=[1,3,4,4,5]H = [1, 3, 4, 4, 5], S=[0,1,1,1,1]S = [0, 1, 1, 1, 1].
  • After the fourth event, H=[1,3,4,4,5]H = [1, 3, 4, 4, 5], S=[0,1,2,1,2]S = [0, 1, 2, 1, 2].
  • The result of the last event (i.e., query event 11) is S[0]+⋯+S[4]=6S[0] + \cdots + S[4] = 6.

Therefore, this function should return [3,6][3, 6].

Sample 22

Consider the following call:

tower_events([7, 7, 9, 5, 8, 10, 2, 9, 2, 2], [[1], [6, 8, 6], [1], [1, 9], [3], [8], [2, 4], [5], [1, 1, 7], [1], [0, 9]])

This function should return [5,3,10][5, 3, 10].

Translated by ChatGPT 5