A14311 | Little Alawn's Puzzle
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
When he's not training for IOI, Little Alawn enjoys playing with puzzles of various types to stimulate his brain. Today, he's playing with a puzzle that consists of a $2 \times n$ grid where each row is a permutation of the numbers $1,2,3,\ldots,n$ .
The goal of Little Alawn's puzzle is to make sure no numbers on the same column or row are the same (we'll call this state of the puzzle as solved), and to achieve this he is able to swap the numbers in any column. However, after solving the puzzle many times, Little Alawn got bored and began wondering about the number of possible solved configurations of the puzzle he could achieve from an initial solved configuration only by swapping numbers in a column.
Unfortunately, Little Alawn got stuck while trying to solve this harder problem, so he was wondering if you could help him with it. Find the answer modulo $10^9+7$ .
The goal of Little Alawn's puzzle is to make sure no numbers on the same column or row are the same (we'll call this state of the puzzle as solved), and to achieve this he is able to swap the numbers in any column. However, after solving the puzzle many times, Little Alawn got bored and began wondering about the number of possible solved configurations of the puzzle he could achieve from an initial solved configuration only by swapping numbers in a column.
Unfortunately, Little Alawn got stuck while trying to solve this harder problem, so he was wondering if you could help him with it. Find the answer modulo $10^9+7$ .
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 10^4$ ). Description of the test cases follows.
The first line of each test case contains a single integer $n$ ( $2 \le n \le 4 \cdot 10^5$ ).
The next two lines of each test case describe the initial state of the puzzle grid. Each line will be a permutation of the numbers $1,2,3,\ldots,n$ and the numbers in each column and row will be pairwise distinct.
It is guaranteed that the sum of $n$ over all test cases does not exceed $4 \cdot 10^5$ .
The first line of each test case contains a single integer $n$ ( $2 \le n \le 4 \cdot 10^5$ ).
The next two lines of each test case describe the initial state of the puzzle grid. Each line will be a permutation of the numbers $1,2,3,\ldots,n$ and the numbers in each column and row will be pairwise distinct.
It is guaranteed that the sum of $n$ over all test cases does not exceed $4 \cdot 10^5$ .
输出格式
For each test case output a single integer, the number of possible solved configurations of the puzzle Little Alawn can achieve from an initial solved configuration only by swapping numbers in a column. As the answer can be very large, please output it modulo $10^9+7$ .
The answer for each test case should be on a separate line.
The answer for each test case should be on a separate line.
输入输出样例
输入 #1
2 4 1 4 2 3 3 2 1 4 8 2 6 5 1 4 3 7 8 3 8 7 5 1 2 4 6
输出 #1
2 8
The two possible puzzle configurations for example $1$ are:
- $[1,4,2,3]$ in the first row and $[3,2,1,4]$ in the second;
- $[3,2,1,4]$ in the first row and $[1,4,2,3]$ in the second.
- $[1,4,2,3]$ in the first row and $[3,2,1,4]$ in the second;
- $[3,2,1,4]$ in the first row and $[1,4,2,3]$ in the second.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted