请求添加hack
查看原帖
请求添加hack
777081
Geoyster楼主2023/11/12 23:35
5 2
2 20
4 18
6 16
8 14
10 12
1 100
5 19

答案应为 1。

以下代码可以通过本题,但是对上述数据无法得到正确答案。

#include<bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 5e5 + 2;

int n,m;
struct cd{
	int x,y;
	bool operator<(const cd o)const{
		return x<o.x;
	}
}a[N],b[N],c[N],d[N];
int stx[N],tp;
ll ans;

void work(cd *_a,cd *_c,int &_n,bool op){
	sort(_a+1,_a+1+_n);
	stx[tp=1]=1;
	for(int i=2;i<=_n;i++){
		if(!op){
			while(_a[stx[tp]].y<=_a[i].y&&tp>0) tp--;
			stx[++tp]=i;
		} else {
			if(_a[i].y<_a[stx[tp]].y) stx[++tp]=i;
		}
	}
	for(int i=1;i<=tp;i++){
		_c[i]=_a[stx[i]];
	}
	_n=tp;
}

void solve(int l,int r,int ql,int qr){
	int mid=l+r>>1,opt=ql;
	ll res=0;
	for(int i=ql;i<=qr;i++){
		if(1ll*(d[i].x-c[mid].x)<0) continue;
		ll now=1ll*(d[i].x-c[mid].x)*(d[i].y-c[mid].y);
		if(res<now){
			res=now;  opt=i;
		}
	}
	ans=max(ans,res);
	if(l<mid) solve(l,mid-1,ql,opt);
	if(r>mid) solve(mid+1,r,opt,qr);
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
//	freopen("data.txt","r",stdin);
//	freopen("std.txt","w",stdout);
	cin>>m>>n;
	for(int i=1;i<=m;i++){
		cin>>a[i].x>>a[i].y;
	}
	for(int i=1;i<=n;i++){
		cin>>b[i].x>>b[i].y;
	}
	work(a,c,m,1);  work(b,d,n,0);
	solve(1,m,1,n);
	cout<<ans;
	return 0;
}
2023/11/12 23:35
加载中...