#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <deque>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#define lowbit(x) ((x) & -(x))
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
const int maxn = 1e5 + 7;
const int INF = 0x3f3f3f3f;
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const double pi = acos(-1.0);
inline int read(){
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if (ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
struct node{
int id, value;
}a[maxn];
bool cmp(node a, node b){
return a.value < b.value;
}
bool cmp1(node a, node b){
return a.value > b.value;
}
vector<int>v[maxn];
int vis[maxn];
int main(){
//ios::sync_with_stdio(false);
//freopen("text.txt","r",stdin);
//freopen("out1.txt","w",stdout);
int t, n, k;
cin >> t;
while (t --){
n = read();
k = read();
set<int>S;
S.clear();
for (int i = 0; i < n; i ++){
a[i].value = read();
a[i].id = i;
S.insert(a[i].value);
v[i].clear();
vis[i] = false;
}
set<int>::iterator it;
int num = 0;
unordered_map<int,int>mp;
mp.clear();
for (it = S.begin(); it != S.end(); it ++, num ++)
mp[*it] = num;
sort(a,a+n,cmp);
for (int i = 0; i < n; i ++)
v[mp[a[i].value]].push_back(i);
int flag = 0;
for (int i = 0; i < n; i ++){
int x = mp[a[i].value];
int len = v[x].size();
for (int j = 0; j < len; j ++){
if (abs(v[x][j] - a[i].id) % k == 0 && !vis[v[x][j]]){
vis[v[x][j]] = true;
flag ++;
break;
}
}
}
if (flag == n)
cout << "yes" << endl;
else {
flag = 1;
sort(a,a+n,cmp1);
for (int i = 0; i < n; i ++)
v[i].clear(), vis[i] = false;
for (int i = 0; i < n; i ++)
v[mp[a[i].value]].push_back(i);
int flag = 0;
for (int i = 0; i < n; i ++){
int x = mp[a[i].value];
int len = v[x].size();
for (int j = 0; j < len; j ++){
if (abs(v[x][j] - a[i].id) % k == 0 && !vis[v[x][j]]){
vis[v[x][j]] = true;
flag ++;
break;
}
}
}
if (flag == n)
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
Another Birthday Present! CodeChef - SHUFFLE
最新推荐文章于 2021-11-28 19:48:29 发布