题解:CF1893A Anonymous Informant
std__int64_t · · 题解
五年级蒟蒻的第六篇题解,望通过。
题目传送门,CF。
正着操作你就会发现,每个不动点会变到数组的最后一个,但正着不好做,我们就反着来。
首先我们知道操作就是回退
不难发现,当
其实每次模拟不一定要回退整个数组,只需要维护当前的最后一个在原数组的哪里即可。用
我们发现
code
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int t, n, k, a[N], now;
bool v[N];
bool Solve(){
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
now = n;
fill(v + 1, v + n + 1, 0);
while(k-- && !v[now]){
v[now] = 1;
int x = a[now];
if(x > n) return 0;
now = (now - x + n - 1) % n + 1;
}
return 1;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> t;
while(t--){
cout << (Solve() ? "Yes" : "No") << '\n';
}
return 0;
}