比赛 CSP2022提高组 评测结果 TTTTTTTTTTTTTEETTEEE
题目名称 策略游戏 最终得分 0
用户昵称 张恒畅 运行时间 17.375 s
代码语言 C++ 内存使用 68.22 MiB
提交时间 2022-10-30 11:24:29
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
int a[N];
int b[N];
int c[N];
int d[4010][4010];
int n, m, q;
int l1, r1, l2, r2;
bool cmp1(int x, int y)
{
	return x > y;
}
int main()
{
	freopen("csp2022_game.in","r",stdin);
	freopen("csp2022_game.out","w",stdout);
	cin >> n >> m >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for(int i = 1; i <= m; i++) {
		cin >> b[i];
	}
	while(q--) {
		memset(c, 0, sizeof(c));
		memset(d, 0, sizeof(d));
		cin >> l1 >> r1 >> l2 >> r2;
		if(l1 == r1) {
			int t = 0;
			for(int i = l2; i <= r2; i++) {
				t++;
				c[t] = a[l1] * b[i];
			}
			sort(c+1, c+t+1);
			cout << c[1] << endl;
			continue;
		}

		if(l2 == r2) {
			int t = 0;
			for(int i = l1; i <= r1; i++) {
				t++;
				c[t] = b[l2] * a[i];
			}
			sort(c+1, c+t+1, cmp1);
			cout << c[1] << endl;
			continue;
		}
//缩小矩阵求每行最小值最大
		int fi = 0, se = 0;
		for(int i = l1; i <= r1; i++) {
			fi++;
			se = 0;
			for(int j = l2; j <= r2; j++) {
				se++;
				d[fi][se] = a[i] * b[j];
			}
		}

		
		
		for(int i = 1; i <= fi; i++) {
        sort(d[i]+1, d[i] + 1 + se);
		}	
		
	    ///////////////////tiaoshi
//		for(int i = 1; i <= fi; i++)
//		 {
//		 for(int j = 1; j <= se; j++)
//		 {
//		 cout << d[i][j] <<" " ;	
//	     }	
//	     cout << endl;
//		 }
		////////////////////tiaoshi
		
		int t = 0;
		for(int i = 1; i <= fi; i++)
		{
		t++;
		c[t] = d[i][1];	
		}
		///
//		cout << t << endl;
//	    for(int i = 1; i <= t; i++)
//	    cout << c[i] <<" ";
	    ///
		sort(c+1, c+t+1, cmp1);
		t = 0;
		cout << c[1] << endl;
		fi = 0, se = 0;
	}
	return 0;
}