【补题】Codeforces Round 779 (Div. 2) C. Shinju and the Lost Permutation
题意:
思路: CF1658C 题解 - 洛谷专栏
感觉很蠢QAQ
很明显当最大值移动到首位的时候,答案为1
那么我们只要判断Y/N,所以一定有个什么办法判定即可,不如直接把1移动到第一位来想,这个不用多说吧,就是方便更好的操作和思考
因为尾部值移动上来,如果比当前队首小的话,一定会产生贡献值+1的情况,而大于队首,减少的贡献是都有可能的
因此只要贡献值增加大于2,就是错误
感觉就是很莫名其妙……根本没想到这种地方……太诡异了,训少了
代码:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS \std::ios::sync_with_stdio(0); \std::cin.tie(0); \std::cout.tie(0)const int N = 3e5 + 5;
const int INF = 1e18;
const int MOD = 998244353;
// const int MOD=1e9+7;
// const int MOD=100003;
const int maxn=5e5+10;void solve(){int n;cin >> n;vector<int> ve(n);int st=-1;int f=0;for(int i=0;i<n;i++){cin >> ve[i];if(ve[i]==1 && st!=-1){f=1;}else if(ve[i]==1){st=i;}}if(st==-1 || f==1){cout << "NO\n";return ;}for(int i=st,cnt=0;cnt<n;cnt++,i=(i+1)%n){if(ve[(i+1)%n]-ve[i]>1){cout << "NO\n";return ;}}cout << "YES\n";}signed main(){IOS;int t=1;cin >> t;while(t--){solve();}
}