#595
Unrated
Mountains
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Note: the time limit for this problem is 5s, 2.5 times the default. The memory limit is twice the default.

There are NN (1N20001 \leq N \leq 2000) evenly spaced mountains in a row on the edge of Farmer John's farm. These can be expressed as an array of heights h1,h2,,hNh_1,h_2,\dots,h_N. For a mountain ii, you can see another mountain jj if there are no mountains strictly higher than the line of sight connecting the tops of mountain jj and ii. Formally, for two mountains i<ji < j, they can see each other if there is no kk such that i<k<ji < k < j and (k,hk)(k, h_k) is above the line segment connecting (i,hi)(i, h_i) and (j,hj)(j, h_j). There are QQ (1Q20001 \leq Q \leq 2000) updates where the height of one mountain increases. Find the total number of unordered pairs of mountains that see each other after each update.

입력

Line 11 contains NN.

Line 22 contains NN heights h1,h2,,hNh_1,h_2,\dots,h_N (for each ii, 0hi1090 \leq h_i \leq 10^9).

Line 33 contains QQ.

Lines 44 to 3+Q3+Q contain xx, yy (1xN1 \leq x \leq N, 1y1 \leq y) where xx is the index of the mountain and yy is the amount the height increases by. It is guaranteed that the new height of the mountain is at most 10910^9.

출력

QQ lines, with the total number of unordered pairs of mountains that see each other after each update.

예제 입력 1

5
2 4 3 1 5
3
4 3
1 3
3 2

예제 출력 1

7
10
7

점수

Tests 2-5 satisfy N,Q100N, Q\le 100. Tests 6-11 satisfy Q10Q \leq 10. Tests 12-21 have no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.