Logo
(追記) (追記ここまで)

33200번 - Parking Theory 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB0000.000%

문제

Sharif University has a rectangular parking lot with $n \times m$ spaces for cars. Each row and column of the parking lot has entrances at both ends.

The parking lot is full, and the order in which the cars entered is given for each parking space. Specifically, a cell with the number 1ドル$ is the first car that entered the parking lot, and a cell with the number $n \cdot m$ is the last one to enter.

Abolfazl has a theory about how cars park in this lot. He believes that any car entering the parking lot from a specific side (row or column) moves straight until it finds its parking spot and never changes direction. Moreover, a car cannot pass through a cell that already contains a parked car.

Abolfazl wants to count the number of subgrids in the parking lot that satisfy this condition. A subgrid is valid if all cars in that subgrid can park without violating the above rules, considering only the cars within the subgrid.

Help Abolfazl determine the number of such valid subgrids.

입력

The first line of input contains two integers $n$ and $m$ (1ドル \le n, m \le 500$), the number of rows and columns of the parking lot. Each of the following $n$ lines contains $m$ integers, indicating the order of entry of the cars. It is guaranteed that numbers are different between 1ドル$ and $n \cdot m$.

출력

Print a single integer, the number of valid subgrids in the parking lot.

제한

예제 입력 1

2 3
1 2 5
3 4 6

예제 출력 1

18

힌트

출처

ICPC > Regionals > Asia West Continent > Iran > 2024 ICPC Asia Tehran Regional Contest J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /