#FT0000062. Đếm giao cắt giữa các đường cao tốc (Japan)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm giao cắt giữa các đường cao tốc (Japan)
Japan
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Japan plans to build straight superhighways between cities on the eastern and western coasts of a long island. There are cities on the east coast and on the west coast. Cities on either coast are numbered from north to south.
Each highway connects a city on the east coast to a city on the west coast. A crossing occurs when two highways intersect in the interiors of their segments. Sharing a city endpoint is not counted as a crossing. No three highway interiors meet at the same point.
Count the pairs of highways that cross, counting each pair once.
Input
The first line contains , the numbers of eastern cities, western cities, and highways.
Each of the following lines contains integers , denoting the highway from eastern city to western city .
Output
Print one integer: the number of crossing highway pairs.
Subtasks
-
Subtask 1 (20 points): ; ; , for every highway; the endpoint pairs are distinct.
-
Subtask 2 (30 points): ; ; , for every highway; the endpoint pairs are distinct.
-
Subtask 3 (50 points): ; ; , for every highway; the endpoint pairs are distinct.
Examples
Input
3 4 4
1 4
2 3
3 2
3 1
Output
5
Explanation
The highways connect , , , and , with eastern coordinates first. Highway crosses each of the other three highways, contributing . Highway crosses both highways starting at eastern city , contributing more.
The highways and share an endpoint and are not counted as crossing. Hence .