比赛 CSP2022提高组 评测结果 AAWWWAAAWWWWTWWTTWWW
题目名称 策略游戏 最终得分 25
用户昵称 湖岸与夜与咸鱼 运行时间 3.946 s
代码语言 C++ 内存使用 5.35 MiB
提交时间 2022-10-30 09:37:49
显示代码纯文本
// 河南省实验中学 高中 21级 关天泽

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define re register

const int INF = 0x3f3f3f3f;
const int N = 100005;
using namespace std;

ll a[N], b[N];
int n, m, q;

ll t1[N<<2], t2[N<<2];

void build(int p, int l, int r){
	if (l == r){
		t1[p] = b[l];
		t2[p] = b[l];
		return;
	}
	int mid = (l + r) >> 1;
	build(2 * p, l, mid);
	build(2 * p + 1, mid + 1, r);
	t1[p] = min(t1[2 * p], t1[2 * p + 1]);
	t2[p] = max(t2[2 * p], t2[2 * p + 1]);
	return;
}

ll ask1(int p, int l, int r, int L, int R){
	if(l >= L && r <= R) return t1[p];
	ll ans = INF;
	int mid = (l + r) >> 1;
	if (L <= mid) ans = min(ans, ask1(2 * p, l, mid, L, R));
	if (R > mid) ans = min(ans, ask1(2 * p + 1, mid + 1, r, L, R));
	return ans;
}

ll ask2(int p, int l, int r, int L, int R){
	if(l >= L && r <= R) return t2[p];
	ll ans = -INF;
	int mid = (l + r) >> 1;
	if (L <= mid) ans = max(ans, ask2(2 * p, l, mid, L, R));
	if (R > mid) ans = max(ans, ask2(2 * p + 1, mid + 1, r, L, R));
	return ans;
}

ll getmin(int l, int r){
	return ask1(1, 1, m, l, r);
}

ll getmax(int l, int r){
	return ask2(1, 1, m ,l, r);
}

int main(){
	freopen("csp2022_game.in", "r", stdin);
	freopen("csp2022_game.out", "w", stdout);
	cin >> n >> m >> q;
	for (re int i = 1; i <= n; i++) cin >> a[i];
	for (re int i = 1; i <= m; i++) cin >> b[i];
	if (n > 2000 || m > 2000){
		while(q--){
			int l1, r1, l2, r2;
			cin >> l1 >> r1 >> l2 >> r2;
			if (l1 == r1){
				ll ans = INF;
				for (re int i = l2; i <= r2; i++) ans = min(ans, a[l1] * b[i]);
				cout << ans << endl;
			}
			if (l2 == r2){
				ll ans = -INF;
				for (re int i = l1; i <= r1; i++) ans = max(ans, a[i] * b[l2]);
				cout << ans << endl;
			}
		}
		return 0;
	}
	build(1, 1, m);
	while(q--){
		int l1, l2, r1, r2;
		cin >> l1 >> r1 >> l2 >> r2;
		ll maxx = getmax(l2, r2);
		ll minn = getmin(l2, r2);
		ll ans = -INF;
		for (re int i = l1; i <= r1; i++) ans = max(ans, a[i] < 0?a[i] * maxx:a[i] * minn);
		cout << ans << endl;
	}
	return 0;
}