#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = __int128;
using ii = pair<int, int>;
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const ll MOD = 1e9 + 7;
const ll MX = 1e9;
ll N, X[500001], Y[500001], st[2000005], ST[2000005]; set<ll> S;
void build(ll v, ll l, ll r) {
if(l == r) {
st[v] = X[l]; ST[v] = Y[l];
return;
}
build(v * 2, l, (l + r) / 2);
build(v * 2 + 1, (l + r) / 2 + 1, r);
st[v] = st[v * 2] * st[v * 2 + 1] % MOD;
ST[v] = max(ST[v * 2], ST[v * 2 + 1]);
}
void update(ll v, ll l, ll r, ll p) {
if(l == r) {
st[v] = X[l], ST[v] = Y[l];
return;
}
ll md = (l + r) / 2;
if(p <= md) update(v * 2, l, md, p);
else update(v * 2 + 1, md + 1, r, p);
st[v] = st[v * 2] * st[v * 2 + 1] % MOD;
ST[v] = max(ST[v * 2], ST[v * 2 + 1]);
}
ll query(ll v, ll l, ll r, ll lo, ll hi) {
if(l > hi || r < lo) return 1;
if(l >= lo && r <= hi) return st[v];
return query(v * 2, l, (l + r) / 2, lo, hi) * query(v * 2 + 1, (l + r) / 2 + 1, r, lo, hi) % MOD;
}
ll Query(ll v, ll l, ll r, ll lo, ll hi) {
if(l > hi || r < lo) return 0;
if(l >= lo && r <= hi) return ST[v];
return max(Query(v * 2, l, (l + r) / 2, lo, hi),
Query(v * 2 + 1, (l + r) / 2 + 1, r, lo, hi));
}
ll solve() {
if(S.empty()) return ST[1];
auto it = S.end(); it--;
ll v = 1; vector<ll> arr;
while(v <= MX) {
v *= X[*it]; arr.pb(*it);
if(it == S.begin()) break;
it--;
}
reverse(arr.begin(), arr.end());
v = 1; ll best = 0;
for(ll l = 0; l < (ll)arr.size(); l++) {
v *= X[arr[l]];
best = max(best, v * Y[arr[l]]);
if(l < arr.size() - 1)
best = max(best, v * Query(1, 0, N - 1, arr[l], arr[l + 1] - 1));
else best = max(best, v * Query(1, 0, N - 1, arr[l], N - 1));
}
if(v <= MX) best = max(best, Query(1, 0, N - 1, 0, arr[0] - 1)), best %= MOD;
else best = best % MOD * query(1, 0, N - 1, 0, arr[0] - 1) % MOD;
return best;
}
int init(int n, int x[], int y[]) {
N = n;
for(int l = 0; l < N; l++) {
X[l] = x[l], Y[l] = y[l];
if(X[l] > 1) S.insert(l);
}
build(1, 0, N - 1);
return solve() % MOD;
}
int updateX(int pos, int val) {
if(X[pos] > 1) S.erase(pos);
X[pos] = val;
if(X[pos] > 1) S.insert(pos);
update(1, 0, N - 1, pos);
return solve() % MOD;
}
int updateY(int pos, int val) {
Y[pos] = val;
update(1, 0, N - 1, pos);
return solve() % MOD;
}
Compilation message
horses.cpp: In function 'll solve()':
horses.cpp:66:28: warning: conversion from 'll' {aka '__int128'} to 'std::vector<__int128>::size_type' {aka 'long unsigned int'} may change value [-Wconversion]
66 | v *= X[arr[l]];
| ^
horses.cpp:67:44: warning: conversion from 'll' {aka '__int128'} to 'std::vector<__int128>::size_type' {aka 'long unsigned int'} may change value [-Wconversion]
67 | best = max(best, v * Y[arr[l]]);
| ^
horses.cpp:69:65: warning: conversion from 'll' {aka '__int128'} to 'std::vector<__int128>::size_type' {aka 'long unsigned int'} may change value [-Wconversion]
69 | best = max(best, v * Query(1, 0, N - 1, arr[l], arr[l + 1] - 1));
| ^
horses.cpp:69:75: warning: conversion from 'll' {aka '__int128'} to 'std::vector<__int128>::size_type' {aka 'long unsigned int'} may change value [-Wconversion]
69 | best = max(best, v * Query(1, 0, N - 1, arr[l], arr[l + 1] - 1));
| ~~^~~
horses.cpp:70:66: warning: conversion from 'll' {aka '__int128'} to 'std::vector<__int128>::size_type' {aka 'long unsigned int'} may change value [-Wconversion]
70 | else best = max(best, v * Query(1, 0, N - 1, arr[l], N - 1));
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:83:28: warning: conversion from 'll' {aka '__int128'} to 'int' may change value [-Wconversion]
83 | return solve() % MOD;
| ~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:90:28: warning: conversion from 'll' {aka '__int128'} to 'int' may change value [-Wconversion]
90 | return solve() % MOD;
| ~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:95:28: warning: conversion from 'll' {aka '__int128'} to 'int' may change value [-Wconversion]
95 | return solve() % MOD;
| ~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 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 |
340 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 |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
300 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
448 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
7 ms |
348 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
4 ms |
468 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1159 ms |
85064 KB |
Output is correct |
2 |
Correct |
538 ms |
85060 KB |
Output is correct |
3 |
Correct |
525 ms |
88752 KB |
Output is correct |
4 |
Correct |
689 ms |
92668 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 |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 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 |
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 |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
6 ms |
456 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
4 ms |
468 KB |
Output is correct |
32 |
Correct |
6 ms |
468 KB |
Output is correct |
33 |
Correct |
79 ms |
56840 KB |
Output is correct |
34 |
Correct |
67 ms |
56904 KB |
Output is correct |
35 |
Correct |
248 ms |
95036 KB |
Output is correct |
36 |
Correct |
237 ms |
94840 KB |
Output is correct |
37 |
Correct |
183 ms |
55068 KB |
Output is correct |
38 |
Correct |
148 ms |
71784 KB |
Output is correct |
39 |
Correct |
54 ms |
54768 KB |
Output is correct |
40 |
Correct |
218 ms |
90016 KB |
Output is correct |
41 |
Correct |
108 ms |
54860 KB |
Output is correct |
42 |
Correct |
133 ms |
54932 KB |
Output is correct |
43 |
Correct |
218 ms |
90280 KB |
Output is correct |
44 |
Correct |
212 ms |
90316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 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 |
340 KB |
Output is correct |
16 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
7 ms |
456 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
452 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
7 ms |
472 KB |
Output is correct |
33 |
Correct |
1155 ms |
88912 KB |
Output is correct |
34 |
Correct |
499 ms |
97516 KB |
Output is correct |
35 |
Correct |
547 ms |
88948 KB |
Output is correct |
36 |
Correct |
654 ms |
92660 KB |
Output is correct |
37 |
Correct |
80 ms |
56860 KB |
Output is correct |
38 |
Correct |
77 ms |
56804 KB |
Output is correct |
39 |
Correct |
256 ms |
95292 KB |
Output is correct |
40 |
Correct |
272 ms |
94852 KB |
Output is correct |
41 |
Correct |
163 ms |
54992 KB |
Output is correct |
42 |
Correct |
163 ms |
71752 KB |
Output is correct |
43 |
Correct |
56 ms |
54724 KB |
Output is correct |
44 |
Correct |
256 ms |
90060 KB |
Output is correct |
45 |
Correct |
113 ms |
54840 KB |
Output is correct |
46 |
Correct |
138 ms |
55020 KB |
Output is correct |
47 |
Correct |
257 ms |
90452 KB |
Output is correct |
48 |
Correct |
234 ms |
90624 KB |
Output is correct |
49 |
Correct |
305 ms |
60192 KB |
Output is correct |
50 |
Correct |
254 ms |
60208 KB |
Output is correct |
51 |
Correct |
558 ms |
96868 KB |
Output is correct |
52 |
Correct |
404 ms |
96252 KB |
Output is correct |
53 |
Correct |
1193 ms |
58484 KB |
Output is correct |
54 |
Correct |
535 ms |
76336 KB |
Output is correct |
55 |
Correct |
207 ms |
55908 KB |
Output is correct |
56 |
Correct |
394 ms |
91844 KB |
Output is correct |
57 |
Correct |
760 ms |
56464 KB |
Output is correct |
58 |
Correct |
1062 ms |
56996 KB |
Output is correct |
59 |
Correct |
210 ms |
90316 KB |
Output is correct |