시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
3 초 | 512 MB | 162 | 55 | 47 | 38.211% |
You are going to hold an international programming contest in a rectangular hall, which has HW seats arranged in H rows and W columns. The rows are numbered from 0 through H - 1 and the columns are numbered from 0 through W - 1. The seat in row r and column c is denoted by (r, c). You invited HW contestants, numbered from 0 through HW - 1. You also made a seating chart, which assigns the contestant i (0 ≤ i ≤ HW - 1) to the seat (Ri, Ci). The chart assigns exactly one contestant to each seat.
A set of seats in the hall S is said to be rectangular if there are integers r1, r2, c1, and c2 satisfying the following conditions:
A rectangular set consisting of k seats (1 ≤ k ≤ HW) is beautiful if the contestants whose assigned seats are in the set have numbers from 0 through k - 1. 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 Q such requests numbered from 0 through Q - 1 in chronological order. The request j (0 ≤ j ≤ Q - 1) is to swap the seats assigned to contestants Aj and Bj. You accept each request immediately and update the chart. After each update, your goal is to compute the beauty of the current seating chart.
You should implement the following procedure and function:
give_initial_chart(int H, int W, int[] R, int[] C)
H
, W
: the number of rows and the number of columns.R
, C
: arrays of length HW representing the initial seating chart.swap_seats
.int swap_seats(int a, int b)
a
, b
: contestants whose seats are to be swapped.Let H = 2, W = 3, R = [0, 1, 1, 0, 0, 1], C = [0, 0, 1, 1, 2, 2], and Q = 2.
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.
0 | 3 | 4 |
1 | 2 | 5 |
Let's say the grader calls swap_seats(0, 5)
. After the request 0, the seating chart is as follows.
5 | 3 | 4 |
1 | 2 | 0 |
The sets of seats corresponding to the contestants {0}, {0, 1, 2}, and {0, 1, 2, 3, 4, 5} are rectangular and beautiful. Thus, the beauty of this seating chart is 3, and swap_seats
should return 3.
Let's say the grader calls swap_seats(0, 5)
again. After the request 1, the seating chart goes back to the initial state. The sets of seats corresponding to the contestants {0}. {0, 1}, {0, 1, 2, 3}, and {0, 1, 2, 3, 4, 5} are rectangular and beautiful. Hence, the beauty of this seating chart is 4, and swap_seats
should return 4.
a
≤ HW - 1 for any call to swap_seats
b
≤ HW - 1 for any call to swap_seats
a
≠ b
for any call to swap_seats
번호 | 배점 | 제한 |
---|---|---|
1 | 5 | HW ≤ 100, Q ≤ 500 |
2 | 6 | HW ≤ 10,000, Q ≤ 5,000 |
3 | 20 | H ≤ 1,000, W ≤ 1,000, Q ≤ 5,000 |
4 | 6 | Q ≤ 5,000, | |
5 | 33 | H = 1 |
6 | 30 | No additional constraints |
The sample grader reads the input in the following format:
Here, Aj and Bj are parameters for the call to swap_seats
for the request j.
The sample grader prints your answers in the following format:
swap_seats
for the request jOlympiad > International Olympiad in Informatics > IOI 2018 > Day 1 2번
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)