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

11859번 - Marriage questions 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB226436.364%

문제

Once upon a time in a country far, far away, the wise king had M beautiful daughters. At last, the time for them to get married has come. King sent a message in N neighboring kingdoms, so each of them sent a prince to marry one of the princesses.

As a loving father the king considered his daughters’ opinions. First of all he arranged young men in a line, enumerated them with numbers from 1 to N, and asked each of his daughters, with whom from those candidates she was agree to get married.

King had an excellent mathematical background, so it was easy for him to check whether it is possible to find a husband for each of his daughters in such way, that requests of each daughter were satisfied. But suddenly the king thought about more interesting question: how many pairs (L, R) (1 ≤ L ≤ R ≤ N) are there, such that it is possible to assign a husband for each daughter, using only candidates with numbers from L to R inclusive?

Help king to find an answer to his question!

입력

First line contains three integers N, M and K (1 ≤ N ≤ 30 000, 1 ≤ M ≤ 2 000, 1 ≤ K ≤ min(N · M, 100 000)) — number of candidates, number of girls and number of lines, describing girls’ preferences respectively.

In next K lines there are two integers Ai, Bi (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ M), it means that girl Bi likes candidate Ai. All pairs are different.

출력

Output the number of ways king can choose a pair (L, R) to satisfy the problem statement.

제한

예제 입력 1

5 3 7
1 1
1 2
1 3
2 3
3 2
4 2
5 1

예제 출력 1

4

힌트

In the sample test pairs (1, 3),(1, 4),(1, 5) and (2, 5) satisfy the required conditions.

출처

Olympiad > International Zhautykov Olympiad > IZhO 2014 F번

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

출처

대학교 대회

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

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