昨天的div2 B题。 代码如下
#include <bits/stdc++.h>
#define INF 1e18 + 7
#define EPS 1e-18
#define MOD 1000000007
#define TEN5 100010
#define TEN6 1000010
#define nline '\n'
#define int long long
#define double long double
using namespace std;
void test_case() {
int n, x;
cin >> n >> x;
vector<pair<int, int> > a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i].first;
a[i].second = i;
}
if(2*x<=n){cout<<"Yes"<<endl;return;}
stable_sort (a.begin(), a.end());
for (int i = 0; i < n; ++i) {
int p = a[i].second;
if (p != i && p - x < 0 && p + x >= n) {
puts("NO");
return;
}
// if (p + x >= n && p - x >= 0 && i > n - 1 - x && i < x) {
// puts("NO");
// return;
// }
}
puts("YES");
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
test_case();
}
//system("pause");
return 0;
}
样例
4
3 3
3 2 1
4 3
1 2 3 4
5 2
5 1 2 3 4
5 4
1 2 3 4 4
实测本地正常输出,在线出错。
ps(还有一个问题。自己昨天敲的,第二题总是1109th用例出错。test 2的1109th是yes,test 4的1109th是no,test8的1109th是yes。代码,希望大佬指点)