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

19469번 - Reachable Sequences 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 512 MB4110571.429%

문제

ZZX has a sequence $a,ドル which is a permutation of 1,ドル 2, \ldots, n$. Now ZZX wants to perform some modifications on this sequence. For each modification, he can choose a pair of integers $i$ and $j,ドル satisfying 1ドル \le i < j \le n$ and $a_i > a_j,ドル and then swap $a_i$ and $a_j$.

If a permutation $b$ can be obtained by performing some (possibly zero) modifications on the initial sequence $a,ドル then ZZX says $b$ is reachable from $a$.

Now JRY has $m$ sequences $a^{(1)},ドル $a^{(2)},ドル $\ldots,ドル $a^{(m)}$. Each of them is a permutation of 1,ドル 2, \ldots, n$. He wants to know how many pairs $(i, j)$ such that 1ドル \le i \le m$ and 1ドル \le j \le m$ have the property that $a_i$ is reachable from $a_j$.

입력

The first line contains an integer $T$. Then $T$ test cases follow. In each test case:

The first line contains two integers $n$ and $m$. After that, $m$ lines follow. The $k$-th of them contains $n$ integers $a^{(k)}_1,ドル $a^{(k)}_2,ドル $\ldots,ドル $a^{(k)}_n$. Each $a^{(k)}$ is a permutation of 1,ドル 2, \ldots, n$.

There are at most 1000ドル$ small test cases and 1ドル$ large test case. The small test cases satisfy 1ドル \le n \le 5$ and 1ドル \le m \le 500$. The large test case satisfies 1ドル \le n \le 9$ and 1ドル \le m \le 3 \cdot 10^5$.

출력

For each test case, print the answer on a separate line.

제한

예제 입력 1

2
3 3
1 2 3
3 1 2
2 3 1
2 2
1 2
1 2

예제 출력 1

5
4

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2016 > Day 4: Ce Bin and Ryyi Ji Contest 1 E번

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

출처

대학교 대회

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

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