WA 45 pts,玄关求调!
查看原帖
WA 45 pts,玄关求调!
807826
zjpwdyf楼主2024/5/15 19:23

Rt,提交记录,估计是细节没处理好。

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6 + 5;
struct node{
	ll x, id;	
}a[N];
bool cmp(node A, node B){
	return A.x < B.x;
}
ll n, m, p, xp, x0, ans = -1; //xp : p点的下标,x0 同理
ll L[N], R[N], id[N], tot;
int main(){
	cin >> n >> m >> p;
	for(int i = 1; i <= n; i++){
		scanf("%lld", &a[i].x);
		a[i].id = i;
	}
	sort(a, a + n + 1, cmp);
	for(int i = 0; i <= n; i++){
		if(a[i].id == p) xp = i;
		if(a[i].id == 0) x0 = i;
	}
	if(xp > x0){
		reverse(a, a + n + 1);
		for(int i = 0; i <= n; i++) a[i].x *= -1;
		xp = n - xp, x0 = n - x0;
	}
	for(int i = 0; i <= n; i++) id[a[i].id] = i;
	int l = 0, r = 0, flag = (a[xp].x * 2 >= -(m + 5));
	if(flag) m += 5;
	while(a[l].x * 2 < -m) l++;
	while(a[r].x < 0) r++;
	for(; a[l].x <= 0; l++){
		if(l > xp && flag) m -= 5, flag = 0;
		while(r < n && a[r + 1].x - a[l].x <= m / 2) r++;
		if(r - l == ans)
			L[++tot] = l, R[tot] = r;
		else if(r - l > ans){
			ans = r - l;
			tot = 1;
			L[tot] = l, R[tot] = r;
		}
	}
	cout << ans << endl;
	l = 1, r = tot;
	for(int i = 1; i <= n; i++){ //贪心
		int x = id[i];
		if(x < x0){
			int tr = lower_bound(L + l, L + r + 1, x) - L;
			if(tr <= r) r = min(r, tr);
		}
		else{
			int tl = lower_bound(R + l, R + r + 1, x) - R;
			if(tl <= r) l = max(l, tl);
		}
	}
	for(int i = L[l]; i <= R[l]; i++)
		if(i != x0) printf("%lld ", a[i].id);	
	return 0;
}
2024/5/15 19:23
加载中...