#P3913. 车的攻击
车的攻击
Description
On an chessboard, there are rooks. The -th rook is located at row and column . Find the number of cells attacked by at least one rook.
A rook can attack all cells in the same row or the same column.
Input Format
The first line contains 2 integers .
The next lines each contain 2 integers .
Output Format
Output one integer, the number of cells that are attacked.
3 2
1 2
2 2
7
Hint
• For 30% of the testdata, .
• For 60% of the testdata, .
• For 100% of the testdata, $1 \le N \le 10^9; 1 \le K \le 10^6; 1 \le R_i, C_i \le N$.
Translated by ChatGPT 5
京公网安备 11011102002149号