fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. #define loop(i,a,b) for(ll i = (ll)a ; i < (ll)b ; i++)
  5. #define rtloop(i,a,b) for(ll i = (ll)a; i >= (ll)b; i--)
  6. #define pb push_back
  7. #define mp make_pair
  8. #define yo(a) cerr <<#a <<" = " << a <<"\n";
  9. #define COOL ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  10.  
  11.  
  12.  
  13. void solve(){
  14. ll t;
  15. cin >> t;
  16. while(t--){
  17. ll n, k;
  18. cin >> n >> k;
  19. ll a[n+1];
  20. map<ll,ll> m;
  21. vector<pair <ll,ll> >v;
  22. loop(i,1,n+1){
  23. cin >> a[i];
  24. v.pb(mp(a[i], i));
  25. m[a[i]]++;
  26. }
  27. sort(v.begin(), v.end());
  28. if(k == 1){
  29. cout << "yes\n";
  30. continue;
  31. }
  32. ll i = 1;
  33. bool fl = 0;
  34. ll curr;
  35. ll summ = 0;
  36. vector<pair<ll,ll> > :: iterator it = v.begin();
  37. while(it != v.end()){
  38. summ = 0;
  39. auto it2 = it;
  40. it2 ++;
  41. summ += (abs(it -> second - i)%k);
  42. while(it2 != v.end() && it2 -> first == it -> first){
  43. i++;
  44. summ += (abs(it2 -> second - i)%k);
  45. it2++;
  46. }
  47. if(summ % k != 0){
  48. fl = 1;
  49. break;
  50. }
  51. it = it2;
  52. i++;
  53. }
  54. if(fl)cout <<"no\n";
  55. else cout << "yes\n";
  56. }
  57.  
  58.  
  59.  
  60. }
  61.  
  62.  
  63.  
  64. int main() {
  65. #ifndef ONLINE_JUDGE
  66. freopen("inn.txt", "r", stdin);
  67. freopen("op.txt", "w", stdout);
  68. #endif
  69. COOL
  70. solve();
  71.  
  72.  
  73.  
  74.  
  75. return 0;
  76. }
  77.  
  78.  
  79.  
  80.  
Success #stdin #stdout 0s 4560KB
stdin
Standard input is empty
stdout
Standard output is empty