原题链接
#include <bits/stdc++.h>
using namespace std;
#define io ios::sync_with_stdio(0);cin.tie(0)
#define LL long long
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define fi first
#define se second
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
string solve() {
int n; cin >> n;
vector<int> a(n);
for(auto &v : a)
cin >> v;
if(count(a.begin(), a.end(), 1) != 1)
return "NO";
int p = find(a.begin(), a.end(), 1) - a.begin();
rotate(a.begin(), a.begin() + p, a.end());
for(int i = 1; i < n; i ++) {
if(a[i] - a[i-1] > 1)
return "NO";
}
return "YES";
}
int main() {
int T; cin >> T;
while(T --) {
cout << solve() << endl;
}
return 0;
}
|