记录编号 577288 评测结果 AAAAAAAAAAAATWWTTWWW
题目名称 [CSP 2022S]策略游戏 最终得分 60
用户昵称 Gravatar湖岸与夜与咸鱼 是否通过 未通过
代码语言 C++ 运行时间 3.846 s
提交时间 2022-10-30 12:52:53 内存使用 6.68 MiB
显示代码纯文本
// 河南省实验中学 高中 21级 关天泽

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

const ll INF = 0x3f3f3f3f3f3f3f3f;
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);
}

signed 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;
}