Japanese Lottery

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

Amida-kuji is a lottery popular in Japan, which can be used to assign ww prizes to ww people. The game consists of ww vertical lines, called legs, and some horizontal bars that connect adjacent legs. The tops of the legs are the starting positions of the ww people, and the prizes are at the bottom of the legs. To determine the prize of the iith person, one has to move down on the iith leg, starting at the top, and switch the leg whenever a horizontal bar is encountered. You can see such a game and how to trace a path in Figure J.1.

You want to manipulate the lottery in such a way that the iith person gets the iith prize, for every ii, by removing some horizontal bars. Since you do not want to get caught, you want to remove as few bars as possible.

Figure J.1: Visualization of an Amida-kuji game. The first person is connected to the third prize. This is also Sample Input 2 after all connections are added and before any connection is removed. To connect the iith person to the iith prize, it suffices to remove both horizontal bars between legs 22 and 33 and the topmost horizontal bar between legs 33 and 44. This is the only minimal solution.

For this problem, the initial game configuration has no horizontal bars. Then, horizontal bars are added one by one or are removed again. After each change, you want to know the minimum number of horizontal bars that need to be removed such that the iith prize is assigned to the iith person for each ii. Note that this is always possible by removing all horizontal bars.

입력

The input consists of:

  • One line with three integers w,hw, h and qq (2w202 \leq w \leq 20, 1h,q21051\leq h,q \leq 2\cdot10^5), the number of legs, the height of the legs, and the number of changes.
  • qq lines, each containing three integers y,x_1y, x\_{1} and x_2x\_{2} (1yh1\leq y \leq h, 1x_1,x_2w1\leq x\_{1}, x\_{2} \leq w), describing a change where a horizontal bar is added or removed at height yy between legs x_1x\_1 and x_2x\_2. If there is already a horizontal bar at this position, it will be removed. Otherwise the bar will be added. It is guaranteed that the two legs are adjacent, i.e. x_1x_2=1|x\_{1}-x\_{2}|=1.

It is guaranteed that all horizontal bars have different heights at every moment.

출력

After each change, output a single integer, the minimum number of horizontal bars that need to be removed in the game with the currently existing bars such that the iith prize is assigned to the iith person for each ii.