포럼
문제 ICPC00379

J. Japanese Lottery

설명

Amida-kuji is a lottery popular in Japan, which can be used to assign \(w\) prizes to \(w\) people. The game consists of \(w\) vertical lines, called legs, and some horizontal bars that connect adjacent legs. The tops of the legs are the starting positions of the \(w\) people, and the prizes are at the bottom of the legs. To determine the prize of the \(i\)th person, one has to move down on the \(i\)th 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 .

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

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 \(i\)th prize is assigned to the \(i\)th person for each \(i\). Note that this is always possible by removing all horizontal bars.

제약
입력 형식

The input consists of:
- One line with three integers \(w, h\) and \(q\) (\(2 \leq w \leq 20\), \(1\leq h,q \leq 2\cdot10^5\)), the number of legs, the height of the legs, and the number of changes.
- \(q\) lines, each containing three integers \(y, x_{1}\) and \(x_{2}\) (\(1\leq y \leq h\), \(1\leq x_{1}, x_{2} \leq w\)), describing a change where a horizontal bar is added or removed at height \(y\) between legs \(x_1\) and \(x_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_{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 \(i\)th prize is assigned to the \(i\)th person for each \(i\).

예제 1
입력
4 6 7
1 1 2
2 3 4
4 3 4
5 1 2
6 3 4
3 2 3
6 3 4
출력
1
2
1
0
1
2
1
예제 2
입력
5 9 12
1 3 4
2 1 2
3 2 3
4 4 5
5 2 1
6 4 3
7 2 3
8 4 3
9 4 5
6 4 3
7 2 3
1 3 4
출력
1
2
3
4
3
2
3
4
3
4
3
2
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC GCPC 2023

평가 및 의견

J. Japanese Lottery

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

J. Japanese Lottery

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8