求助,为什么输出都是0?
查看原帖
求助,为什么输出都是0?
761313
Hohlistro楼主2022/11/15 18:16
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;
long long a[maxn],b[maxn];
long long c;

//[1]最大正数,[2]最大负数,[3]最小正数,[4]最小负数,[5]是否有零
int ac[5],bc[5];
int at[5],bt[5];

void srch(long long *v,int vl,int vr,int op){
	int *p,*x;
	if(op == 1)	{p = ac; x =at;}
	else	{p = bc; x = bt;}
	memset(x,0,sizeof(x));
	for(int j=vl;j<=vr;j++){
		if(v[j] > 0){
			if(x[1])
				if(v[j] > v[p[1]])	p[1] = j;
			else	{p[1] = j; x[1] = 1;}
			if(x[3])
				if(v[j] < v[p[3]])	p[3] = j;
			else	{p[3] = j; x[3] = 1;}
		}
		else if(v[j] < 0){
			if(x[2])
				if(v[j] > v[p[2]])	p[2] = j;
			else	{p[2] = j; x[2] = 1;}
			if(x[4])
				if(v[j] < v[p[4]])	p[4] = j;
			else	{p[4] = j; x[4] = 1;}
		}
		else{
			if(!x[5]){
				x[5] = 1;
				p[5] = j;
			}
		}
	}
	return;	
}


int main(){
//	freopen("game.in","r",stdin);
//	freopen("game.out","w",stdout);
	int n,m,q;
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=m;i++)
		cin>>b[i];
	int al,ar,bl,br;
	while(q--){
		cin>>al>>ar>>bl>>br;
		srch(a,al,ar,1);
		srch(b,bl,br,2);
		if((!at[1] && !at[3] && at[5]) || (!bt[1] && !bt[3] && bt[5]))
			c = 0;
		else if(!at[2] && !at[4]){
			if(!bt[2] && !bt[4]){
				if(bt[5])	c = 0;
				else c = b[bc[3]] * a[ac[1]];
			}
			else{
				if(at[5])	c = 0;
				else c = a[ac[3]] * b[bc[4]];
			}
		}
		else if(!at[1] && !at[3]){
			if(!bt[1] && !bt[3]){
				if(bt[5])	c = 0;
				else c = b[bc[2]] * a[ac[4]];
			}
			else{
				if(at[5])	c = 0;
				else c = a[ac[2]] * b[bc[1]];
			}
		}
		else{
			if(!bt[1] && !bt[3]){
				if(bt[5])	c = 0;
				else c = b[bc[2]] * a[ac[4]];
			}
			else if(!bt[2] && !bt[4]){
				if(bt[5])	c = 0;
				else c = b[bc[3]] * a[ac[1]];
			}
			else{
				if(at[5]) c = 0;
				else	c = max(a[ac[3]]*b[bc[4]],a[ac[2]]*b[bc[1]]);
			}
		}
		cout<<c<<endl;
	}
	return 0;
} 
2022/11/15 18:16
加载中...