QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#410603#6665. 팀 만들기thenymphsofdelphi0 36ms8784kbC++174.1kb2024-05-14 10:20:302024-05-14 10:20:31

Judging History

你现在查看的是最新测评结果

  • [2024-05-14 10:20:31]
  • 评测
  • 测评结果:0
  • 用时:36ms
  • 内存:8784kb
  • [2024-05-14 10:20:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#if __cplusplus < 202002L
template <class T> int ssize(const T& a){ return a.size(); }
#endif
template <class T1, class T2> istream& operator>> (istream& in, pair <T1, T2>& a){ in >> a.first >> a.second; return in; }
template <class T> istream& operator>> (istream& in, vector <T>& a){ for (auto &x: a){ in >> x; } return in; }
 
using ll = long long;
using ld = long double;

template<class T, class F>
struct sparse_table{
#ifdef LOCAL
	#define ASSERT(x) assert(x)
#else
	#define ASSERT(x) 42
#endif
	int n;
	vector<vector<T>> data;
	F TT;
	T T_id;
	sparse_table(F TT, T T_id): TT(TT), T_id(T_id){ }
	sparse_table &operator=(const sparse_table &st){
		n = st.n;
		data = st.data;
		return *this;
	}
	friend void swap(sparse_table &stl, sparse_table &str){
		swap(stl.n, str.n);
		swap(stl.data, str.data);
	}
	// O(n * log(n))
	void build(const vector<T> &a){
		n = (int)a.size();
		data.assign({a});
		for(auto p = 1, i = 1; p << 1 <= n; p <<= 1, ++ i){
			data.emplace_back(n - (p << 1) + 1);
			for(auto j = 0; j < (int)data[i].size(); ++ j) data[i][j] = TT(data[i - 1][j], data[i - 1][j + p]);
		}
	}
	// O(1)
	T query(int l, int r) const{
		ASSERT(0 <= l && l <= r && r <= n);
		if(l == r) return T_id;
		int d = __lg(r - l);
		return TT(data[d][l], data[d][r - (1 << d)]);
	}
#undef ASSERT
};
template<class T, class F>
auto make_sparse_table(F TT, T T_id){
	return sparse_table(TT, T_id);
}
template<class T>
auto make_rminq(T inf = numeric_limits<T>::max()){
	return sparse_table([&](const T &x, const T &y){ return min(x, y); }, inf);
}
template<class T>
auto make_rmaxq(T minf = numeric_limits<T>::min()){
	return sparse_table([&](const T &x, const T &y){ return max(x, y); }, minf);
}

vector <ll> build_teams(vector <int> A1, vector <int> B1, vector <int> A2, vector <int> B2, vector <int> L1, vector <int> R1, vector <int> L2, vector <int> R2){
	auto n = ssize(A1), m = ssize(A2), q = ssize(L1);

	vector <ll> ans(q);

	if ((n <= 500 and m <= 500 and q <= 500) or q <= 20){
		for (auto iq = 0; iq < q; iq++){
			vector <pair <ll, int>> opt(n);

			auto dnc = [&](auto&& self, int l1, int r1, int l2, int r2)->void{
				auto m1 = (l1 + r1) >> 1;
				opt[m1] = {numeric_limits <ll>::min(), -1};
				for (auto j = l2; j <= r2; j++){
					opt[m1] = max(opt[m1], pair <ll, int>{ll(A1[m1] + A2[j]) * (B1[m1] + B2[j]), j});
				}
				auto m2 = opt[m1].second;
				if (l1 <= m1 - 1){
					self(self, l1, m1 - 1, m2, r2);
				}
				if (m1 + 1 <= r1){
					self(self, m1 + 1, r1, l2, m2);
				}
			};
			dnc(dnc, L1[iq], R1[iq], L2[iq], R2[iq]);

			ll tans = max_element(begin(opt), end(opt))->first;
			ans[iq] = tans;
		}
	}
	if (*max_element(begin(L2), end(L2)) == 0 and *min_element(begin(R2), end(R2)) == m - 1){
		vector <pair <ll, int>> opt(n);

		auto dnc = [&](auto&& self, int l1, int r1, int l2, int r2)->void{
			auto m1 = (l1 + r1) >> 1;
			opt[m1] = {numeric_limits <ll>::min(), -1};
			for (auto j = l2; j <= r2; j++){
				opt[m1] = max(opt[m1], pair <ll, int>{ll(A1[m1] + A2[j]) * (B1[m1] + B2[j]), j});
			}
			auto m2 = opt[m1].second;
			if (l1 <= m1 - 1){
				self(self, l1, m1 - 1, m2, r2);
			}
			if (m1 + 1 <= r1){
				self(self, m1 + 1, r1, l2, m2);
			}
		};
		dnc(dnc, 0, n - 1, 0, m - 1);

		auto rmq = make_rminq(numeric_limits <pair <ll, int>>::max());
		rmq.build(opt);

		for (auto iq = 0; iq < q; iq++){
			auto tans = rmq.query(L1[iq], R1[iq] + 1).first;
			ans[iq] = tans;
		}
	}

	return ans;
}

#ifndef ONLINE_JUDGE
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	if (fopen("KEK.inp", "r")){
		freopen("KEK.inp", "r", stdin);
		freopen("KEK.out", "w", stdout);
	}

	int n, m, q;
	cin >> n >> m >> q;
	vector <int> A1(n), B1(n), A2(m), B2(m), L1(q), R1(q), L2(q), R2(q);
	cin >> A1 >> B1 >> A2 >> B2;
	for (auto iq = 0; iq < q; iq++){
		cin >> L1[iq] >> R1[iq] >> L2[iq] >> R2[iq];
	}

	vector <ll> ans = build_teams(A1, B1, A2, B2, L1, R1, L2, R2);
	for (auto iq = 0; iq < q; iq++){
		cout << ans[iq] << "\n";
	}
}
#endif

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 0ms
memory: 3824kb

input:

500 499
7 4997
13 4988
20 4983
28 4969
44 4963
49 4922
54 4919
58 4897
71 4893
72 4886
85 4883
102 4879
107 4876
113 4868
128 4845
133 4839
135 4831
138 4821
140 4809
156 4793
178 4780
181 4776
190 4760
196 4756
203 4752
209 4736
225 4728
228 4723
232 4720
235 4709
253 4676
258 4660
260 4645
266 463...

output:

25745327
24221652
25260576
25444230
25944610
26027379
25944610
21794500
25502475
19748843
25944610
25269202
25294500
24084151
25944610
25944610
25923420
25745327
24097815
21842574

result:

ok 20 lines

Test #2:

score: 5
Accepted
time: 1ms
memory: 3688kb

input:

500 499
3 4994
6 4989
12 4978
20 4972
22 4965
32 4949
48 4914
52 4893
56 4875
62 4867
66 4860
80 4840
98 4828
106 4814
108 4788
127 4785
142 4783
177 4775
181 4770
182 4766
191 4764
201 4757
205 4753
235 4743
298 4740
300 4725
326 4720
346 4714
350 4709
373 4703
379 4680
390 4674
391 4643
393 4640
3...

output:

22404249
24625440
24983847
24994621
26178282
25385964
25028495
18972628
24778368
24808000
25212965
24604640
23302608
24979302
22241460
25385964
24155109
26178282
25137864
25619090

result:

ok 20 lines

Test #3:

score: 5
Accepted
time: 1ms
memory: 3748kb

input:

500 499
3 4988
4 4967
8 4953
10 4942
11 4936
13 4930
20 4927
40 4904
43 4897
61 4892
65 4852
70 4849
74 4815
78 4812
90 4801
91 4792
107 4783
116 4781
121 4770
123 4747
125 4738
129 4706
132 4700
134 4698
139 4684
145 4680
148 4667
155 4665
164 4652
181 4651
188 4649
191 4648
199 4646
202 4628
209 4...

output:

25458244
17507070
23722057
23685867
24493896
26156980
21925946
26222616
25564880
25172184
24611064
17491437
25418853
25931580
25669456
25144644
26156980
25931580
17224980
25581918

result:

ok 20 lines

Test #4:

score: 0
Wrong Answer
time: 4ms
memory: 3840kb

input:

500 499
22 5000
23 4994
33 4971
34 4960
35 4949
36 4943
37 4930
66 4891
112 4879
118 4863
132 4859
136 4854
152 4851
153 4848
154 4845
164 4842
180 4814
184 4801
197 4798
211 4794
214 4789
221 4773
226 4770
250 4768
256 4760
265 4728
267 4727
272 4718
288 4693
313 4691
318 4683
340 4676
352 4662
355...

output:

23575869
23575869
24786000
23703254
23575869
24304230
24149310
23575869
23575869
23575869
23575869
24480170
23575869
23693172
23575869
23575869
23575869
24303166
24531760
24480170
23575869
23693172
23703254
23575869
23575869
23575869
23575869
23575869
24844032
24480170
23575869
24480170
24480170
235...

result:

wrong answer 1st lines differ - expected: '25267216', found: '23575869'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #47:

score: 0
Wrong Answer
time: 35ms
memory: 8660kb

input:

200 100000
335635 996427627
4368692 990235584
10335314 971208588
11639195 971143844
23801483 970115479
31489602 959110431
31544396 956821351
48348198 954187112
48509739 953684848
51173262 952420589
53207608 941523603
62582103 940608015
65545228 932323862
73708623 932037283
80559453 929148992
9033280...

output:

957125526365642416
947997538997015860
1018934869267445340
964594846479779216
966659050232788080
998022851928911032
1018934869267445340
976373818286301248
957125526365642416
967015110829296900
962683441087520775
989206678055651560
957125526365642416
957125526365642416
947997538997015860
9479975389970...

result:

wrong answer 1st lines differ - expected: '993958698780308505', found: '957125526365642416'

Subtask #4:

score: 0
Wrong Answer

Test #65:

score: 0
Wrong Answer
time: 36ms
memory: 8784kb

input:

200 100000
2904660 993940483
16886371 993289642
17317405 990982034
18403947 976774733
18849359 973351068
19183185 970254940
19306003 966229683
21192298 964806508
23734314 964320708
23888967 955733824
27113148 951453312
37031360 944529530
39266197 937051115
40090929 928931574
59651306 922916360
69712...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 1st lines differ - expected: '1016308928382908236', found: '0'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%