luogu#P4898. [IOI 2018] seats 排座位
[IOI 2018] seats 排座位
Background
This is an interactive problem, but here you should submit a full program.
Problem Description
You are going to hold an international programming contest in a rectangular hall. The hall has seats ( rows and columns). Rows are numbered from to , and columns are numbered from to . The seat in row and column is denoted by . There are contestants, numbered from to . You have prepared a seating plan: contestant is assigned to seat . The seating plan is a one-to-one correspondence between contestants and seats.
A set of seats in the hall is called rectangular if there exist integers , and such that:
- .
- .
- is exactly the set of all seats that satisfy and .
If a rectangular set of seats contains seats, and the contestant IDs assigned to these seats are exactly from to , then this set is nice. The niceness of a seating plan is defined as the number of nice rectangular seat sets in the plan.
After you finish the seating plan, you will receive some requests to swap the seats of two contestants. Specifically, there are such requests, numbered from to in time order. Request wants to swap the seats of contestants and . You accept each request immediately and update the seating plan. After each update, your task is to compute the niceness of the current seating plan.
Input Format
The first line contains three positive integers , as described above.
The next lines each contain two non-negative integers. In these lines, line contains , i.e., the row and column of the initial seat of contestant .
The next lines each contain two non-negative integers. In these lines, line contains , i.e., the IDs of the two contestants whose seats should be swapped in request .
Output Format
Output lines. Each line contains one integer. The integer on line is the niceness of the current seating plan after processing swap request in time order.
2 3 2
0 0
1 0
1 1
0 1
0 2
1 2
0 5
0 5
3
4
1 5 3
0 0
0 1
0 2
0 3
0 4
0 1
0 3
4 0
5
3
2
Hint
Constraints
- .
- .
- .
- .
- .
- $(R_i, C_i) \neq (R_j, C_j)(0 \leq i < j \leq HW - 1)$.
- .
- .
- .
- .
Subtasks
-
- (5 points) , .
-
- (6 points) , .
-
- (20 points) , , .
-
- (6 points) , .
-
- (33 points) .
-
- (30 points) No additional constraints.
Translated by ChatGPT 5