#include "horses.h"
#include <vector>
#include <algorithm>
#include <cassert>
#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 5
// 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[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 min(MOD, subl*subr);
// }
// void update_xs(int pos, int value, int l, int r, int index) {
// int mid = (l+r)/2;
// if (l==r) xs[index] = value;
// if (pos <= mid){
// update_xs(pos, value, l, mid, index*2);
// } else {
// update_xs(pos, value, mid+1, r, index*2+1);
// }
// xs[index] = min(MOD, xs[index*2]*xs[index*2+1]);
// }
// ll query_ys(int L, int R, int l, int r, int index) {
// if (r<L || l>R) return 0;
// if (l>=L and r<=R) return ys[index];
// int mid = (l+r)/2;
// ll subl = query_ys(L, R, l, mid, index*2);
// ll subr = query_ys(L, R, mid+1, r, index*2+1);
// return max(subl, subr);
// }
// void update_ys(int pos, int value, int l, int r, int index) {
// int mid = (l+r)/2;
// if (l==r) ys[index] = value;
// if (pos <= mid){
// update_ys(pos, value, l, mid, index*2);
// } else {
// update_ys(pos, value, mid+1, r, index*2+1);
// }
// ys[index] = max(ys[index*2], ys[index*2+1]);
// }
// int solve() {
// int max_i = n-1;
// ll pop = xs[n-1];
// for(int i=n-2; i>=0; i--) {
// if (ys[i] > ys[max_i]*pop) {
// max_i = i;
// pop=1;
// }
// pop = min(pop*xs[i], (ll)MOD);
// }
// pop=1;
// for(int i=0; i<=max_i; i++){
// pop = (pop*xs[i])%MOD;
// }
// return (int) ((pop*ys[max_i])%MOD);
// }
// int init(int N, int X[], int Y[]) {
// n = N;
// xs = v<ll> (2*n, 1);
// ys = v<ll> (2*n, 0);
// for (int i=0; i<n; i++) {
// update_xs(i, X[i], 0, n-1, 1);
// update_ys(i, Y[i], 0, n-1, 1);
// }
// return solve();
// }
// int updateX(int pos, int val) {
// update_xs(pos, val, 0, n-1, 1);
// return solve();
// }
// int updateY(int pos, int val) {
// update_ys(pos, val, 0, n-1, 1);
// return solve();
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
212 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
212 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
288 KB |
Output is correct |
20 |
Correct |
0 ms |
288 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
157 ms |
20752 KB |
Output is correct |
2 |
Correct |
189 ms |
20788 KB |
Output is correct |
3 |
Correct |
178 ms |
24564 KB |
Output is correct |
4 |
Correct |
191 ms |
28404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
212 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
292 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
224 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |