#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "horses.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int mod = 1e9 + 7;
const int N = 5e5 + 10;
int n, st[N * 4];
int BIT[N];
int power(int a, int n) {
int ans = 1;
for (; n; n >>= 1)
if (n & 1) ans = 1LL * ans * a % mod;
return ans;
}
void add(int i, int mul) {
for (++i; i < N; i += i & - i) BIT[i] = 1LL * BIT[i] * mul % mod;
}
int get(int i) {
int ans = 1;
for (++i; i; i -= i & - i) ans = 1LL * ans * BIT[i] % mod;
return ans;
}
void add(int id, int L, int R, int i, int val) {
if (L == R) {
st[id] = val;
return;
}
int mid = L + R >> 1;
if (i <= mid) add(id * 2, L, mid, i, val);
else add(id * 2 + 1, mid + 1, R, i, val);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
int get(int id, int L, int R, int u, int v) {
if (u > R || L > v) return -1;
if (u <= L && R <= v) return st[id];
int mid = L + R >> 1;
return max(get(id * 2, L, mid, u, v), get(id * 2 + 1, mid + 1, R, u, v));
}
set <int> s;
int x[N], y[N];
int solve() {
int cur = n;
long long mul = 1, p = 1;
int best = -1;
int i = -1;
while (1) {
int last = *(--s.lower_bound(cur));
if (last == -1) break;
int val = get(1, 0, n - 1, last, cur - 1);
if (best == -1 || 1LL * best * p < val) {
best = val;
i = last;
p = 1;
}
p *= x[last];
mul *= x[last];
cur = last;
if (mul > 1e9) break;
}
int j = (*(--s.end()) == i ? n : *s.upper_bound(i));
return 1LL * get(i) * get(1, 0, n - 1, i, j - 1) % mod;
}
int init(int _n, int X[], int Y[]) {
n = _n;
for (int i = 0; i < n; ++i) x[i] = X[i], y[i] = Y[i];
s.insert(-1);
for (int i = 0; i < n; ++i) if (x[i] != 1) s.insert(i);
for (int i = 0; i < n; ++i) BIT[i + 1] = 1;
for (int i = 0; i < n; ++i) add(i, x[i]);
for (int i = 0; i < n; ++i) add(1, 0, n - 1, i, y[i]);
return solve();
}
int updateX(int i, int val) {
if (x[i] != 1) s.erase(i);
add(i, power(x[i], mod - 2));
x[i] = val;
if (x[i] != 1) s.insert(i);
add(i, x[i]);
return solve();
}
int updateY(int i, int val) {
add(1, 0, n - 1, i, val);
return solve();
}
//
//
//int main() {
//// freopen("test.inp", "r", stdin);
// ios :: sync_with_stdio(0); cin.tie(0);
// int n, m;
// cin >> n;
// int x[n], y[n];
// for (int i = 0; i < n; ++i) cin >> x[i];
// for (int i = 0; i < n; ++i) cin >> y[i];
// cin >> m;
// cout << init(n, x, y) << '\n';
// while (m--) {
// int cmd, i, val;
// cin >> cmd >> i >> val;
// if (cmd == 1) cout << updateX(i, val) << '\n';
// else cout << updateY(i, val) << '\n';
// }
//}
Compilation message
horses.cpp: In function 'int power(int, int)':
horses.cpp:20:22: warning: declaration of 'n' shadows a global declaration [-Wshadow]
20 | int power(int a, int n) {
| ~~~~^
horses.cpp:17:5: note: shadowed declaration is here
17 | int n, st[N * 4];
| ^
horses.cpp:23:40: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
23 | if (n & 1) ans = 1LL * ans * a % mod;
| ~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void add(int, int)':
horses.cpp:28:64: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
28 | for (++i; i < N; i += i & - i) BIT[i] = 1LL * BIT[i] * mul % mod;
| ~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int get(int)':
horses.cpp:33:57: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
33 | for (++i; i; i -= i & - i) ans = 1LL * ans * BIT[i] % mod;
| ~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void add(int, int, int, int, int)':
horses.cpp:42:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int mid = L + R >> 1;
| ~~^~~
horses.cpp: In function 'int get(int, int, int, int, int)':
horses.cpp:51:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
51 | int mid = L + R >> 1;
| ~~^~~
horses.cpp: In function 'int solve()':
horses.cpp:75:13: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
75 | if (mul > 1e9) break;
| ^~~
horses.cpp:78:54: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
78 | return 1LL * get(i) * get(1, 0, n - 1, i, j - 1) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
352 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
916 ms |
42476 KB |
Output is correct |
2 |
Incorrect |
370 ms |
51252 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |