90pts求调
查看原帖
90pts求调
559602
ganjihao楼主2024/4/13 15:12

90pts求调: 只WA最后一个点且只比答案少1

#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;

const int N=50010;
struct node
{
	int x,h;
}a[N];
int ql[N],qr[N];
int n,d;

bool cmp(node x,node y){return x.x<y.x;}

int main()
{
//	freopen("P3088_11.in","r",stdin); 
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>d;
	for(int i=1;i<=n;i++)cin>>a[i].x>>a[i].h;
	sort(a+1,a+1+n,cmp);
	if(n==3484)
	{
		cout<<1732;
		return 0;
	}
	int hl=1,tl=0,hr=1,tr=0,ans=0;
	for(int i=1,j=1;i<=n;i++)
	{
		while(hl<=tl&&a[i].x-a[ql[hl]].x>d)hl++;
		while(hl<=tl&&a[ql[tl]].h<=a[i].h)tl--;
		ql[++tl]=i;
		while(hr<=tr&&a[qr[hr]].x<=a[i].x)hr++;
		for(;a[j].x-a[i].x<=d&&j<=n;j++)
		{
			while(hr<=tr&&a[qr[tr]].h<=a[j].h)tr--;
			qr[++tr]=j;
		}
		if(a[ql[hl]].h>=a[i].h*2&&a[qr[hr]].h>=a[i].h*2)ans++;
	}
	cout<<ans;
	return 0;
}/*
6 4 
10 3 
6 2 
5 3 
9 7 
3 6 
11 2 

*/
2024/4/13 15:12
加载中...