CodeQUEEN 2025 予選 (AtCoder Beginner Contest 410)
G
Longest Chord Chain
AtCoder
⌀ 2242
原题
翻译中…

Problem Statement

翻译中…

There are $2N$ pairwise distinct points, numbered from $1$ to $2N$, on a circle. Starting from point $1$ and going clockwise, the points are arranged as point $2$, point $3$, ..., point $2N$.

翻译中…

You are given $N$ chords on this circle. The endpoints of the $i$-th chord are points $A_i$ and $B_i$, and the $2N$ values $A_1,\ldots,A_N,B_1,\ldots,B_N$ are all distinct.

翻译中…

Perform the following operations on this circle once each in order:

翻译中…
  1. Among the $N$ chords on the circle, choose any number of chords such that no two chosen chords intersect, and delete the remaining chords.
  2. Add one chord freely to the circle.
翻译中…

Find the maximum possible number of intersection points between chords after the operations are completed.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 2\times 10^5$
  • $1 \leq A_i,B_i \leq 2N$
  • The $2N$ values $A_1, \ldots, A_N,B_1,\ldots,B_N$ are pairwise distinct.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

翻译中…

Output

翻译中…

Output the answer.

翻译中…

样例

Input #1
3
1 5
6 3
4 2
Output #1
2
Initially, there are $3$ chords on the circle, as shown in the figure. After deleting the chord connecting points $3$ and $6$ and adding a new chord through the operations, the number of intersection points between chords is $2$. ![Figure](https://img.atcoder.jp/abc410/be5d090022ebeba5ad0aeea63ef1c38b.png) It is impossible to make the number of intersection points between chords $3$ or more, so the answer is $2$. The endpoints of the chord added at the end do not need to be any of the points $1,\ldots, 2N$.
Input #2
4
1 8
2 7
3 6
4 5
Output #2
4
Input #3
3
1 2
3 4
5 6
Output #3
2
题目信息
题号
abc410_g
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。