#include "horses.h"
#include <vector>
#include <algorithm>
#define v vector
#define ll long long
#define MOD ((ll) 1000000007)
#define INF ((ll) 1000000001)
using namespace std;
int *x;
int *y;
int n;
// Subtask 1
// int solve() {
// int ma = 0;
// int pop = 1;
// for(int i=0; i<n; i++) {
// pop*=x[i];
// ma = max(ma, pop*y[i]);
// }
// return ma%MOD;
// }
// int init(int N, int X[], int Y[]) {
// n = N;
// x = X;
// y = Y;
// return solve();
// }
// int updateX(int pos, int val) {
// x[pos] = val;
// return solve();
// }
// int updateY(int pos, int val) {
// y[pos] = val;
// return solve();
// }
//Subtask 2
// int solve() {
// int max_i = n-1;
// ll pop = x[n-1];
// for(int i=n-2; i>=0; i--) {
// if (y[i] > y[max_i]*pop) {
// max_i = i;
// pop=1;
// }
// pop = min(pop*x[i], INF);
// }
// pop=1;
// for(int i=0; i<=max_i; i++){
// pop = (pop*x[i])%MOD;
// }
// return (int) (pop*y[max_i])%MOD;
// }
// int init(int N, int X[], int Y[]) {
// n = N;
// x = X;
// y = Y;
// return solve();
// }
// int updateX(int pos, int val) {
// x[pos] = val;
// return solve();
// }
// int updateY(int pos, int val) {
// y[pos] = val;
// return solve();
// }
// Subtask 3
// v<ll> xs_mults;
// ll query_xs(int L, int R, int l, int r, int index) {
// if (r<L || l>R) return 1;
// if (l>=L and r<=R) return xs_mults[index];
// int mid = (l+r)/2;
// ll subl = query_xs(L, R, l, mid, index*2);
// ll subr = query_xs(L, R, mid+1, r, index*2+1);
// return (subl*subr)%MOD;
// }
// void update_xs(int pos, int value, int l, int r, int index) {
// int mid = (l+r)/2;
// if (l==r){
// xs_mults[index] = value;
// return;
// }
// if (pos <= mid){
// update_xs(pos, value, l, mid, index*2);
// } else {
// update_xs(pos, value, mid+1, r, index*2+1);
// }
// xs_mults[index] = (xs_mults[index*2]*xs_mults[index*2+1])%MOD;
// }
// int solve() {
// int max_i = n-1;
// ll pop = x[n-1];
// for(int i=n-2; i>=0 && i>=n-30; i--) {
// if (y[i] > y[max_i]*pop) {
// max_i = i;
// pop=1;
// }
// pop = min(pop*x[i], INF);
// }
// ll mult = query_xs(0, max_i, 0, n-1, 1);
// return (int) ((mult*y[max_i])%MOD);
// }
// int init(int N, int X[], int Y[]) {
// n = N;
// x = X;
// y = Y;
// xs_mults = v<ll> (4*n, 1);
// for(int i=0; i<n; i++) {
// update_xs(i, x[i], 0, n-1, 1);
// }
// return solve();
// }
// int updateX(int pos, int val) {
// x[pos] = val;
// update_xs(pos, val, 0, n-1, 1);
// return solve();
// }
// int updateY(int pos, int val) {
// y[pos] = val;
// return solve();
// }
// Subtask 4
v<ll> xs_mod;
v<ll> xs_trunc;
v<int> ys_max;
ll query_xs_mod(int L, int R, int l, int r, int index) {
if (r<L || l>R) return 1;
if (l>=L and r<=R) return xs_mod[index];
int mid = (l+r)/2;
ll subl = query_xs_mod(L, R, l, mid, index*2);
ll subr = query_xs_mod(L, R, mid+1, r, index*2+1);
return (subl*subr)%MOD;
}
void update_xs_mod(int pos, int value, int l, int r, int index) {
if (l==r) {
xs_mod[index] = value;
return;
}
int mid = (l+r)/2;
if (pos <= mid){
update_xs_mod(pos, value, l, mid, index*2);
} else {
update_xs_mod(pos, value, mid+1, r, index*2+1);
}
xs_mod[index] = (xs_mod[index*2]*xs_mod[index*2+1])%MOD;
}
ll query_xs_trunc(int L, int R, int l, int r, int index) {
if (r<L || l>R) return 1;
if (l>=L and r<=R) return xs_trunc[index];
int mid = (l+r)/2;
ll subl = query_xs_trunc(L, R, l, mid, index*2);
ll subr = query_xs_trunc(L, R, mid+1, r, index*2+1);
return min(INF, subl*subr);
}
void update_xs_trunc(int pos, int value, int l, int r, int index) {
if (l==r) {
xs_trunc[index] = value;
return;
}
int mid = (l+r)/2;
if (pos <= mid){
update_xs_trunc(pos, value, l, mid, index*2);
} else {
update_xs_trunc(pos, value, mid+1, r, index*2+1);
}
xs_trunc[index] = min(INF, xs_trunc[index*2]*xs_trunc[index*2+1]);
}
int query_ys_max(int L, int R, int l, int r, int index) {
if (r<L || l>R) return -1;
if (l>=L and r<=R) return ys_max[index];
int mid = (l+r)/2;
int subl = query_ys_max(L, R, l, mid, index*2);
int subr = query_ys_max(L, R, mid+1, r, index*2+1);
if (subl == -1) return subr;
if (subr == -1) return subl;
if (y[subl] > y[subr]) return subl;
return subr;
}
void update_ys_max(int pos, int value, int l, int r, int index) {
if (l==r) {
y[pos] = value;
ys_max[index] = pos;
return;
}
int mid = (l+r)/2;
if (pos <= mid){
update_ys_max(pos, value, l, mid, index*2);
} else {
update_ys_max(pos, value, mid+1, r, index*2+1);
}
int subl = ys_max[index*2];
int subr = ys_max[index*2+1];
int ans = 0;
if (subl == -1) ans = subr;
else if (subr == -1) ans = subl;
else if (y[subl] > y[subr]) ans = subl;
else ans = subr;
ys_max[index] = ans;
}
int solve() {
int max_i = query_ys_max(0, n-1, 0, n-1, 1);
int cur = max_i;
while (cur<n-1) {
cur = query_ys_max(cur+1, n-1, 0, n-1, 1);
ll pop = query_xs_trunc(max_i+1, cur, 0, n-1, 1);
if (y[cur]*pop > y[max_i]) {
max_i = cur;
}
}
ll pop = query_xs_mod(0, max_i, 0, n-1, 1);
return (int) ((pop*y[max_i])%MOD);
}
int init(int N, int X[], int Y[]) {
n = N;
y = Y;
xs_trunc = v<ll> (4*n, 1);
xs_mod = v<ll> (4*n, 1);
ys_max = v<int> (4*n, 0);
for (int i=0; i<n; i++) {
update_xs_mod(i, X[i], 0, n-1, 1);
update_xs_trunc(i, X[i], 0, n-1, 1);
update_ys_max(i, Y[i], 0, n-1, 1);
}
return solve();
}
int updateX(int pos, int val) {
update_xs_mod(pos, val, 0, n-1, 1);
update_xs_trunc(pos, val, 0, n-1, 1);
return solve();
}
int updateY(int pos, int val) {
update_ys_max(pos, val, 0, n-1, 1);
return solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
288 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
288 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
288 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
288 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
288 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
288 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
4 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
296 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
300 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
355 ms |
44664 KB |
Output is correct |
2 |
Correct |
353 ms |
44636 KB |
Output is correct |
3 |
Correct |
574 ms |
44724 KB |
Output is correct |
4 |
Correct |
694 ms |
44428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
280 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
292 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
296 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
296 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
329 ms |
47328 KB |
Output is correct |
34 |
Correct |
281 ms |
47360 KB |
Output is correct |
35 |
Correct |
305 ms |
54200 KB |
Output is correct |
36 |
Correct |
292 ms |
54176 KB |
Output is correct |
37 |
Correct |
282 ms |
45552 KB |
Output is correct |
38 |
Correct |
274 ms |
46356 KB |
Output is correct |
39 |
Correct |
260 ms |
45396 KB |
Output is correct |
40 |
Correct |
272 ms |
49376 KB |
Output is correct |
41 |
Correct |
258 ms |
45412 KB |
Output is correct |
42 |
Correct |
263 ms |
45552 KB |
Output is correct |
43 |
Correct |
267 ms |
49688 KB |
Output is correct |
44 |
Correct |
275 ms |
49612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
288 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
284 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
292 KB |
Output is correct |
16 |
Correct |
1 ms |
284 KB |
Output is correct |
17 |
Correct |
0 ms |
280 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
288 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
392 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
324 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
296 KB |
Output is correct |
33 |
Correct |
355 ms |
48124 KB |
Output is correct |
34 |
Correct |
370 ms |
55944 KB |
Output is correct |
35 |
Correct |
570 ms |
48068 KB |
Output is correct |
36 |
Correct |
702 ms |
52032 KB |
Output is correct |
37 |
Correct |
328 ms |
47532 KB |
Output is correct |
38 |
Correct |
277 ms |
47308 KB |
Output is correct |
39 |
Correct |
302 ms |
54220 KB |
Output is correct |
40 |
Correct |
295 ms |
54144 KB |
Output is correct |
41 |
Correct |
284 ms |
45544 KB |
Output is correct |
42 |
Correct |
299 ms |
46356 KB |
Output is correct |
43 |
Correct |
266 ms |
45392 KB |
Output is correct |
44 |
Correct |
276 ms |
49248 KB |
Output is correct |
45 |
Correct |
263 ms |
45476 KB |
Output is correct |
46 |
Correct |
258 ms |
45420 KB |
Output is correct |
47 |
Correct |
303 ms |
49712 KB |
Output is correct |
48 |
Correct |
311 ms |
49716 KB |
Output is correct |
49 |
Correct |
1071 ms |
49360 KB |
Output is correct |
50 |
Correct |
497 ms |
49324 KB |
Output is correct |
51 |
Correct |
430 ms |
56064 KB |
Output is correct |
52 |
Correct |
379 ms |
55552 KB |
Output is correct |
53 |
Correct |
749 ms |
47712 KB |
Output is correct |
54 |
Correct |
498 ms |
48188 KB |
Output is correct |
55 |
Correct |
341 ms |
46404 KB |
Output is correct |
56 |
Correct |
359 ms |
51136 KB |
Output is correct |
57 |
Correct |
379 ms |
47052 KB |
Output is correct |
58 |
Correct |
370 ms |
47604 KB |
Output is correct |
59 |
Correct |
293 ms |
49716 KB |
Output is correct |