#P4198. 楼房重建

    ID: 3128 远端评测题 1000ms 125MiB 尝试: 2 已通过: 1 难度: 8 上传者: 标签>线段树递归块状链表,块状数组,分块

楼房重建

Description

Outside Xiao A’s building is a large construction site with NN buildings under construction. Every day, buildings on this site are torn down and rebuilt, over and over. He often stares out the window, counting how many buildings he can see.

To simplify, we consider the events in a 2D plane. Xiao A is at point (0,0)(0, 0). The ii-th building is represented by a line segment connecting (i,0)(i, 0) and (i,Hi)(i, H_i), where HiH_i is the height of the ii-th building. A building is considered visible if there exists a point on it with height greater than 00 such that the line segment from (0,0)(0, 0) to that point does not intersect any of the segments of buildings 1,2,,i11, 2, \dots, i-1.

The construction lasts for MM days. Initially, all buildings have height 00. On day ii, the crew sets the height of the building with xx-coordinate XiX_i to YiY_i (the height may increase — construction, decrease — demolition, or remain unchanged — meaning the crew effectively did nothing that day). After the crew finishes each day, please tell how many buildings Xiao A can see.

Input Format

The first line contains two positive integers N,MN, M.

The next MM lines each contain two positive integers Xi,YiX_i, Y_i.

Output Format

Output MM lines. On the ii-th line, output one integer denoting the number of buildings visible to Xiao A after day ii.

3 4
2 4
3 6
1 1000000000
1 1
1
1
1
2

Hint

For 100%100\% of the testdata, 1XiN1 \le X_i \le N, 1Yi1091 \le Y_i \le 10^9, 1N,M1051 \le N, M \le 10^5.

Translated by ChatGPT 5