- 东明张展奕's blog
ARC181总结
- 2024-8-6 15:54:27 @
ARC181总结
ARC还是太难了
A
标签: 有脑子🧠都会
题意
###问题陈述
给出 的排列 。
您希望通过执行以下操作零次或多次来满足所有 的 :
-选择整数 ,如T
帽子 。如果 ,则按升序对 的第 至第 项进行排序。然后,如果 ,则按升序对 的第 到第 项进行排序。可以证明在该问题的约束条件下,
对于所有 ,可以满足 ,而对于任何 ,可以进行有限次数的运算。查找所需的最小操作数。
code:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define TRACE 1
#define tcout TRACE && cout
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
const int P = 998244353;
const int Base = 3221225477;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10, M = 2e6 + 10;
int n;
int a[N];
void solve()
{
cin >> n;
bool flag = true;
for(int i=1; i<=n; i++)
{
cin >> a[i];
if(a[i] != i)
{
flag = false;
}
}
if(flag == true)
{
cout << 0 << endl;
return;
}
int maxn = 0;
for(int i=1; i<=n; i++)
{
if(a[i] == i && maxn < a[i])
{
cout << 1 << endl;
return;
}
maxn = max(a[i], maxn);
}
if(a[1] == n && a[n] == 1)
{
cout << 3 << endl;
return;
}
cout << 2 << endl;
}
signed main()
{
int t;
cin >> t;
while(t--)
{
solve();
}
return 0;
}