GoldSpade
2024-11-18 15:47:48
长为
每次操作选择一个
以下的递增都指非严格单调递增,即
容易发现的一点是相邻的两项
接下来序列只剩下
当
当
最后,再反复操作直到整个序列递增即可。
Tips:事实上,上述讨论不包含所有情况,分析一下会发现
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
using namespace std;
const int N = 5e5+5, M = 3e4+5, mod = 1e9+7;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
int n, K;
LL a[N];
vector<int> res;
#define pb(x) push_back(x)
int main() {
FASTIO;
cin >> n >> K;
rep(i, 1, n) cin >> a[i];
if (n == 2) {
if (a[1] <= a[2]) {
cout << "Yes\n";
cout << "0";
return 0;
}
else if (a[2]+K > a[1]) return cout << "No\n", 0;
else {
cout << "Yes\n";
cout << "1\n1";
return 0;
}
}
rep(i, 2, n-1) {
while (a[i] < a[i-1]) {
a[i] += K, a[i+1] += K;
res.pb(i), res.pb(i);
}
}
if (a[n] < a[n-1]) {
while (a[n-1] < a[n]+K) {
a[n-1]+=K, a[n-2]+=K;
res.pb(n-2), res.pb(n-2);
}
res.pb(n-1);
swap(a[n-1], a[n]);
a[n-1]+=K;
while (a[n-1] < a[n-2]) {
res.pb(n-1), res.pb(n-1);
a[n-1] += K, a[n] += K;
}
}
cout << "Yes\n" << res.size() << '\n';
for (auto it : res) cout << it << ' ';
return 0;
}