8672: Grab the Seat!

内存限制:128 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:6 通过:2

题目描述

Oshwiciqwq studies Physics in a shabby classroom in his sophomore year. The classroom has n rows and m columns of seats, which are narrowly set like a matrix. There is a huge screen in the front of the classroom.

The whole classroom can be seen as a plane, and every seat can be seen as a point on it. The set of all seats' coordinates is {(x,y)∣1≤x≤n,1≤y≤m,x∈Z+,y∈Z+}. Additionally, the screen can be seen as a segment, with two endpoints a (0,1) and (0,m).

As a student who loves studying, he always wants to seat in the front row, so that he can see the whole screen clearly. He thinks a seat is good if and only if there are no other people blocking him from seeing the whole screen. Formally, the seat at (a,b) is good if and only if there is no other person sitting on the seat that is on the segment between (a,b) and any point on the segment (0,1)−(0,m) (including endpoints).

However, today he arrived at the classroom as early as usual, only to find kkk people had already taken their seats. What's worse, while he was busy searching for a good seat, some people changed their seats one by one. Totally there are qqq events of changing seats. He is extremely anxious now, so could you please help him count how many seats are good after each of the qqq changing events?

Obviously, a seat can only be occupied by at most one person at the same time.

输入格式


The first line contains four integers n,m,k,q (2n,m2×105,1k2×105,1q200), denoting the number of rows, the number of columns, the number of people already taken seats and the number of changing events.
For the iii-th line in the following k lines, there are two integers xi,yi (1xin,1yim), denoting the coordinates of an occupied seat.
For the iii-th line in the following q lines, there are three integers pi,xi,yi (1≤pi≤k,1≤xi≤n,1xin,1yim), denoting the id of person changing seats and the coordinates of a seat that the person will change to.
It is guaranteed that any coordinate appears only once in the input.

输出格式


The output contains q lines.
For each of the q changing events, print an integer in a single line, denoting the number of good seats at that time.

输入样例 复制

7 6 6 1
3 1
4 2
4 5
6 3
6 5
6 2
6 6 1

输出样例 复制

24

分类标签