IOI '18 P2 - Seats
View as PDFYou are going to hold an international programming contest in a rectangular hall, which has  seats arranged in 
 rows and 
 columns.
The rows are numbered from 
 through 
 and the columns are numbered from 
 through 
.
The seat in row 
 and column 
 is denoted by 
.
You invited 
 contestants, numbered from 
 through 
.
You also made a seating chart, which assigns the contestant 
 
 to the seat 
.
The chart assigns exactly one contestant to each seat.
A set of seats in the hall  is said to be rectangular if there are integers 
, 
, 
, and 
 satisfying the following conditions:
is exactly the set of all seats
such that
and
.
A rectangular set consisting of  seats 
, is beautiful if the contestants whose assigned seats are in the set have numbers from 
 through 
.
The beauty of a seating chart is the number of beautiful rectangular sets of seats in the chart.
After preparing your seating chart, you receive several requests to swap two seats assigned to two contestants.
More precisely, there are  such requests numbered from 
 through 
 in chronological order.
The request 
 
 is to swap the seats assigned to contestants 
 and 
.
You accept each request immediately and update the chart.
After each update, your goal is to compute the beauty of the current seating chart.
Implementation Details
You should implement the following procedure and function:
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C)
: the number of rows and the number of columns.
: arrays of length
representing the initial seating chart.
- This procedure is called exactly once, and before any call to 
swap_seats. 
int swap_seats(int a, int b)
- This function describes a request to swap two seats.
 : contestants whose seats are to be swapped.
- This function is called 
times.
 - This function should return the beauty of the seating chart after the swap.
 
Example
Let , 
, 
, 
, and 
.
The grader first calls give_initial_chart(2, 3, [0, 1, 1, 0, 0, 1], [0, 0, 1, 1, 2, 2]).
At first, the seating chart is as follows.
Let's say the grader calls swap_seats(0, 5).
After the request , the seating chart is as follows.
The sets of seats corresponding to the contestants , 
, and 
 are rectangular and beautiful.
Thus, the beauty of this seating chart is 
, and 
swap_seats should return .
Let's say the grader calls swap_seats(0, 5) again.
After the request , the seating chart goes back to the initial state.
The sets of seats corresponding to the contestants
, 
, 
, and 
 are rectangular and beautiful.
Hence, the beauty of this seating chart is 
, and 
swap_seats should return .
The files sample-01-in and sample-01-out in the zipped attachment package correspond to this example.
Other sample inputs/outputs are also available in the package.
Constraints
for any call to
swap_seatsfor any call to
swap_seatsfor any call to
swap_seats
Subtasks
- (
points)
,
 - (
points)
,
 - (
points)
,
,
 - (
points)
,
for any call to
swap_seats - (
points)
 - (
points) No additional constraints
 
Sample Grader
The sample grader reads the input in the following format:
- line 
:
 - line 
:
 - line 
:
 
Here,  and 
 are parameters for the call to 
swap_seats for the request .
The sample grader prints your answers in the following format:
- line 
: the return value of
swap_seatsfor the request.
 
Attachment Package
The sample grader along with sample test cases are available here.
Comments