E. [CERC 2021] Single-track railway

    远端评测题 4000ms 512MiB

[CERC 2021] Single-track railway

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Description

Trains running on a single-track railway can only meet at the stations. Suppose that a pair of trains simultaneously leave in the opposite directions, one from the initial and the other from the final station, i.e. the initial station in the opposite direction. It is likely that one of the trains will have to wait for the other one at one of the stations along the railway. To minimize the delays, the trains meet at the station such that the waiting time is minimized.

We know the travel time between each two adjacent stations, equal in both directions. Unfortunately, the travel times constantly change because of the works along the railway. You are given the initial travel times and an updated travel time for the affected section after each change. Write a program that computes the shortest possible waiting time for a pair of trains leaving from the opposite ends of the railway after each of the changes.

Input Format

The first line specifies the number of stations, nn. In the second line, n1n-1 numbers are given, corresponding to the initial travel times between the adjacent stations (the ii-th number is the travel time between stations ii and i+1i+1). The third line specifies the number of changes, kk. This is followed by kk lines, each containing two numbers: the first one, j[1,n1]j \in [1, n-1], specifies the station, and the second gives the updated travel time between stations jj and j+1j+1. Keep in mind that the first station is numbered 1 rather than 0.

Output Format

Output k+1k+1 lines, where the ii-th line will contain the shortest possible waiting time after i1i-1 changes (the first one should correspond to the situation before any changes).

6
20 70 40 10 50
2
4 80
2 30

10
0
40

Hint

Comment

At the beginning, the trains leaving in the opposite directions should meet at station 3. The first train will reach that station in 90 minutes, and the second will arrive there in 100 minutes; the waiting time will thus be 10 minutes. Following the first change, the optimal meeting point becomes station 4. Both trains will take 130 minutes to get there, so neither will have to wait. After the second change, they will also meet at station 4. This time, however, the train that arrives first will have to wait for 40 minutes.

Input limits

  • 2n2000002 \leq n \leq 200\,000
  • 0k2000000 \leq k \leq 200\,000
  • All travel times (both the initial and the updated ones) are integers from the interval [1,106][1, 10^6].

ICPC欢乐赛

未参加
状态
已结束
规则
XCPC
题目
8
开始于
2026-2-7 8:30
结束于
2026-2-7 12:30
持续时间
4 小时
主持人
参赛人数
22