样例没过,洛谷100pts合理吗?还是fc命令出错了
查看原帖
样例没过,洛谷100pts合理吗?还是fc命令出错了
452610
csy20070918楼主2022/11/20 14:49
#include <bits/stdc++.h>
using namespace std;
int n,m,q;
typedef long long LL;
typedef pair<long,long> pr;
const int MAXN = 1e5+10;
const LL INF = 1e9+10;
LL a[MAXN],b[MAXN];
struct Node{
	int L,R,pet,gra;
}alpha[4*MAXN+10],beta[4*MAXN+10],pos[4*MAXN+10],neg[4*MAXN+10];
void build(int pos,int L,int R,Node p[]){
	p[pos].L = L,p[pos].R = R;
	if (L == R) return;
	int mid = p[pos].L + p[pos].R >> 1;
	build(pos*2,L,mid,p);
	build(pos*2+1,mid+1,R,p);		
}
void pushup(int u,Node p[]){
	p[u].pet = min(p[u*2].pet,p[u*2+1].pet);
	p[u].gra = max(p[u*2].gra,p[u*2+1].gra);
	return;
}
void update(int u,int pos,int data,Node p[],int c){
	if (p[u].L == pos && p[u].R == pos){
		p[u].pet = p[u].gra = data;
		if (c == 1 && data < 0) p[u].pet = p[u].gra = INF;
		else if (c == -1 && data > 0) p[u].pet = p[u].gra = -INF;
		return; 
	}
	int mid = p[u].L + p[u].R >> 1;
	if (mid < pos) update(u*2+1,pos,data,p,c);
	else update(u*2,pos,data,p,c);
	pushup(u,p);
	return;
}
pr query(int u,int L,int R,Node p[]){
	if (p[u].L >= L && p[u].R <= R){
		return make_pair(p[u].pet,p[u].gra);
	}
	pr res = make_pair(INF,-INF);
	int mid = p[u].L + p[u].R >> 1;
	if (R > mid){
		pr q = query(u*2+1,L,R,p);
		res.first = min(res.first,q.first);
		res.second = max(res.second,q.second);
	}
	if (L <= mid){
		pr q = query(u*2,L,R,p);
		res.first = min(res.first,q.first);
		res.second = max(res.second,q.second);
	}
	return res;
}
void print(LL q){
	cout << q << endl;
	return;
}
int main(){
//	freopen("game3.in","r",stdin);
//	freopen("game.out","w",stdout);
	cin >> n >> m >> q;
	build(1,1,MAXN,alpha);
	build(1,1,MAXN,beta);
	build(1,1,MAXN,pos);
	build(1,1,MAXN,neg);
	for (int i = 1;i <= n;i++){
		cin >> a[i];
		update(1,i,a[i],alpha,0);
		update(1,i,a[i],pos,1);
		update(1,i,a[i],neg,-1);
	} 
	for (int i = 1;i <= m;i++){
		cin >> b[i];
		update(1,i,b[i],beta,0);
	}
	int l1,l2,r1,r2;
	while(q--){
		cin >> l1 >> l2 >> r1 >> r2;
		pr A = query(1,l1,l2,alpha);
		pr B = query(1,r1,r2,beta);
		if (A.second >= 0 && B.first >= 0) {
			print(A.second*B.first);
			continue;
		}
		if (A.second <= 0 && B.first >= 0){
			print(A.second*B.second);
			continue;
		}
		if (B.second <= 0 && A.second <= 0){
			print(A.first*B.second);
			continue;
		}
		if (B.first <= 0 && A.first >= 0){
			print(A.first*B.first);
			continue;
		}
		if (B.second >= 0 && A.second <= 0){
			print(A.second*B.second);
			continue;
		}
		if (B.second <= 0){
			print(A.first*B.second);
			continue;
		}
		pr grea = query(1,l1,l2,pos);
		pr peti = query(1,l1,l2,neg);
		if (A.first <= 0 && A.second >= 0 && B.first <= 0 && B.second >= 0){
			LL ans = max(grea.first*B.first,peti.second*B.second);
			print(ans);
			continue; 
		}
	}
	return 0;
} 
2022/11/20 14:49
加载中...