#include "horses.h"
#include <vector>
#include <algorithm>
#include <climits>
#define v vector
#define ll long long
#define MOD ((ll) 1000000007)
#define INF (((ll) INT_MAX)+1)
using namespace std;
v<ll> xs;
v<ll> ys;
v<ll> xs_mults;
int n;
// Subtask 1
// int solve() {
// int ma = 0;
// int pop = 1;
// for(int i=0; i<n; i++) {
// pop*=xs[i];
// ma = max(ma, pop*ys[i]);
// }
// return ma%MOD;
// }
// int init(int N, int X[], int Y[]) {
// n = N;
// for (int i=0; i<n; i++) {
// xs.push_back(X[i]);
// ys.push_back(Y[i]);
// }
// return solve();
// }
// int updateX(int pos, int val) {
// xs[pos] = val;
// return solve();
// }
// int updateY(int pos, int val) {
// ys[pos] = val;
// return solve();
// }
//Subtask 2
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], INF);
}
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;
for (int i=0; i<n; i++) {
xs.push_back(X[i]);
ys.push_back(Y[i]);
}
return solve();
}
int updateX(int pos, int val) {
xs[pos] = val;
return solve();
}
int updateY(int pos, int val) {
ys[pos] = val;
return solve();
}
// Subtask 3
// int solve() {
// int max_i = n-1;
// ll pop = xs[n-1];
// for(int i=n-2; i>=0 && i>=n-33; i--) {
// if (ys[i] > ys[max_i]*pop) {
// max_i = i;
// pop=1;
// }
// pop = min(pop*xs[i], INF);
// }
// return (int) ((xs_mults[max_i+1]*ys[max_i])%MOD);
// }
// int init(int N, int X[], int Y[]) {
// n = N;
// xs_mults.push_back(1);
// for (int i=0; i<n; i++) {
// xs.push_back(X[i]);
// xs_mults.push_back((xs_mults[i]*X[i])%MOD);
// ys.push_back(Y[i]);
// }
// }
// int updateX(int pos, int val) {
// xs[pos] = val;
// return solve();
// }
// int updateY(int pos, int val) {
// ys[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();
// }
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
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 |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 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 |
224 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 |
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 |
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 |
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 |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
10 ms |
316 KB |
Output is correct |
24 |
Correct |
11 ms |
320 KB |
Output is correct |
25 |
Correct |
11 ms |
320 KB |
Output is correct |
26 |
Correct |
11 ms |
212 KB |
Output is correct |
27 |
Correct |
9 ms |
212 KB |
Output is correct |
28 |
Correct |
10 ms |
212 KB |
Output is correct |
29 |
Correct |
10 ms |
320 KB |
Output is correct |
30 |
Correct |
10 ms |
316 KB |
Output is correct |
31 |
Correct |
6 ms |
212 KB |
Output is correct |
32 |
Correct |
9 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1563 ms |
12208 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 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 |
0 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 |
10 ms |
316 KB |
Output is correct |
24 |
Correct |
10 ms |
212 KB |
Output is correct |
25 |
Correct |
10 ms |
212 KB |
Output is correct |
26 |
Correct |
10 ms |
316 KB |
Output is correct |
27 |
Correct |
10 ms |
212 KB |
Output is correct |
28 |
Correct |
10 ms |
212 KB |
Output is correct |
29 |
Correct |
11 ms |
320 KB |
Output is correct |
30 |
Correct |
11 ms |
316 KB |
Output is correct |
31 |
Correct |
7 ms |
212 KB |
Output is correct |
32 |
Correct |
10 ms |
324 KB |
Output is correct |
33 |
Execution timed out |
1571 ms |
12204 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
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 |
0 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 |
0 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 |
10 ms |
316 KB |
Output is correct |
24 |
Correct |
9 ms |
316 KB |
Output is correct |
25 |
Correct |
10 ms |
212 KB |
Output is correct |
26 |
Correct |
10 ms |
212 KB |
Output is correct |
27 |
Correct |
10 ms |
212 KB |
Output is correct |
28 |
Correct |
10 ms |
212 KB |
Output is correct |
29 |
Correct |
10 ms |
212 KB |
Output is correct |
30 |
Correct |
10 ms |
324 KB |
Output is correct |
31 |
Correct |
7 ms |
212 KB |
Output is correct |
32 |
Correct |
9 ms |
212 KB |
Output is correct |
33 |
Execution timed out |
1570 ms |
12260 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |