PivotOJ

Seats

시간 제한: 3000ms메모리 제한: 512MB출처: IOI 2018BOJ 20062

문제

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 ≤ iHW - 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:

  • 0 ≤ r1r2H - 1.
  • 0 ≤ c1c2W - 1.
  • S is exactly the set of all seats (r, c) such that r1rr2 and c1cc2.

A rectangular set consisting of k seats (1 ≤ kHW) 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 ≤ jQ - 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.

코드를 제출하려면 로그인하세요.