ST表40pts求调
查看原帖
ST表40pts求调
925129
lzdll楼主2024/10/2 09:52
#include<bits/stdc++.h>
#define int long long
#define N 100005
#define R(x) x=read()
using namespace std;
inline int read() {
	int x,y;
	char c=getchar();
	x=0,y=1;
	while(c<'0'||c>'9') {
		if(c=='-') y=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		x=(x<<3ll)+(x<<1ll)+(c^'0');
		c=getchar();
	}
	return x*y;
}
int n,m,q;
struct ST {
	int st1[100005][50],st2[100005][50];//1最大,2最小
	int st3[100005][50],st4[100005][50];//3正数最小,4负数最大
	void init(int x) {
		for(int i=1; i<=x; ++i) {
			int p;R(p);
			st1[i][0]=st2[i][0]=p;
			if(p>=0) {
				st3[i][0]=p;
				st4[i][0]=-0x3f3f3f3f;
			} 
			else{
				st4[i][0]=p;
				st3[i][0]=0x3f3f3f3f;
			}
		}
		for(int j=1; (1ll<<j)<=x; ++j) {
			for(int i=1; i+(1ll<<j)-1<=x; ++i) {
				st1[i][j]=max(st1[i][j-1],st1[i+(1ll<<(j-1))][j-1]);
				st4[i][j]=max(st4[i][j-1],st4[i+(1ll<<(j-1))][j-1]);
				st2[i][j]=min(st2[i][j-1],st2[i+(1ll<<(j-1))][j-1]);
				st3[i][j]=min(st3[i][j-1],st3[i+(1ll<<(j-1))][j-1]);
			}
		}
	}
	int Get1(int l,int r) {
		int e=log2(r-l+1);
		return max(st1[l][e],st1[r-(1ll<<e)+1][e]);
	}	
	int Get2(int l,int r) {
		int e=log2(r-l+1);
		return min(st2[l][e],st2[r-(1ll<<e)+1][e]);
	}
	int Get3(int l,int r) {
		int e=log2(r-l+1);
		return min(st3[l][e],st3[r-(1ll<<e)+1][e]);
	}
	int Get4(int l,int r) {
		int e=log2(r-l+1);
		return max(st4[l][e],st4[r-(1ll<<e)+1][e]);
	}

};
ST A,B;
signed main() {
	R(n),R(m),R(q);
	A.init(n);
	B.init(m);
	while(q--) {
		int l,r,ll,rr;
		R(l),R(r),R(ll),R(rr);
		//1最大,2最小
		//3正数最小,4负数最大
		int a[6],b[6];
		int maxx=-0x3f3f3f3f3f3f3f3f;
		a[1]=A.Get1(l,r),a[2]=A.Get2(l,r), a[3]=A.Get3(l,r),a[4]=A.Get4(l,r);
		b[1]=B.Get1(ll,rr),b[2]=B.Get2(ll,rr),b[3]=B.Get3(ll,rr),b[4]=B.Get4(ll,rr);
		for(int i=1;i<=4;++i){
			int minn=0x3f3f3f3f3f3f3f3f;
			for(int j=1;j<=4;++j){
				if(b[j]==-0x3f3f3f3f||b[j]==0x3f3f3f3f)continue;
				minn=min(minn,a[i]*b[j]);
			}
			maxx=max(maxx,minn);
		}
		cout<<maxx<<"\n";
	}
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}
2024/10/2 09:52
加载中...