99网
您的当前位置:首页Codeforces Round #655 (Div. 2) C. Omkar and Baseball

Codeforces Round #655 (Div. 2) C. Omkar and Baseball

来源:99网

C. Omkar and Baseball


解题思路

  • 我们可以找位置不对的区间有多少个:
  • 具体操作见代码

附上代码

#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
const double PI=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=2e5+10;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;
inline void read(int &x){
    char t=getchar();
    while(!isdigit(t)) t=getchar();
    for(x=t^48,t=getchar();isdigit(t);t=getchar()) x=x*10+(t^48);
}
int a[N];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int ass=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			if(a[i-1]!=i-1&&a[i]==i)
				ass++;
		}
		if(a[n]!=n) ass++;
		if(ass==0)
			cout<<0<<endl;
		else{
			if(ass==1) cout<<1<<endl;
			else cout<<2<<endl;
		} 
	}
	return 0;
}

因篇幅问题不能全部显示,请点此查看更多更全内容