#include <bits/stdc++.h>
using namespace std;
#define lol long long
const lol maxn = 5e5 + 5, maxN = 2e6 + 5, M = 1e9 + 7, MX = INT_MAX;
lol pwr(lol val, lol p) {
if (p==0) return 1;
lol cur = pwr(val, p/2);
cur = cur * cur % M;
if (p%2==1) cur = cur * val % M;
return cur;
}
lol n, x[maxn], y[maxn], all;
lol seg[maxN];
void build(int id, int l, int r) {
if (l==r) {
seg[id] = y[l];
return;
}
int mid = (l+r)/2;
build(id*2, l, mid);
build(id*2+1, mid+1, r);
seg[id] = max(seg[id*2], seg[id*2+1]);
}
void update(int id, int l, int r, int target, int val) {
if (r<target || target<l) return;
if (l==r) {
seg[id] = val;
return;
}
int mid = (l+r)/2;
update(id*2, l, mid, target, val);
update(id*2+1, mid+1, r, target, val);
seg[id] = max(seg[id*2], seg[id*2+1]);
}
lol mx(int id, int l, int r, int findl, int findr) {
if (r<findl || findr<l) return 0;
if (findl<=l && r<=findr) return seg[id];
int mid = (l+r)/2;
return max(mx(id*2, l, mid, findl, findr), mx(id*2+1, mid+1, r, findl, findr));
}
set<int> s;
int32_t solve() {
auto it = next(s.rbegin());
lol cnt1 = 1;
if (*it==-1) return mx(1, 0, n-1, 0, n-1);
while (cnt1 <= MX) {
cnt1 *= x[*it];
it = next(it);
if (*it==-1) break;
}
lol ans = 1;
if (*it == -1) {
it = prev(it);
ans = max(mx(1, 0, n-1, 0, *it-1), ans);
// cout << ans << endl;
}
lol cnt2 = 1;
while (it != s.rbegin()) {
cnt2 *= x[*it];
ans = max(mx(1, 0, n-1, *it, *prev(it) - 1) * cnt2, ans);
// cout << *it << " " << *prev(it)-1 << " " << mx(1, 0, n-1, *it, *prev(it) - 1) << " " << cnt2 << endl;
it = prev(it);
}
ans %= M;
ans = ans * (all * pwr(cnt1, M-2) % M) % M;
return ans;
}
int init(int N, int X[], int Y[]) {
n = N;
all = 1;
s.insert(-1);
s.insert(n);
for (int i=0;i<n;i++) {
x[i] = X[i], y[i] = Y[i];
all = all * x[i] % M;
if (x[i]!=1) s.insert(i);
}
build(1, 0, n-1);
return solve();
}
int updateX(int pos, int val) {
if (val==1) s.erase(pos);
// cout << x[pos] << " " << val << endl;
if (x[pos]==1 && val!=1) {
s.insert(pos);
// cout << "test" << endl;
}
all = all * pwr(x[pos], M-2) % M;
x[pos] = val;
all = all * val % M;
return solve();
}
int updateY(int pos, int val) {
update(1, 0, n-1, pos, val);
return solve();
}
Compilation message
horses.cpp: In function 'int32_t solve()':
horses.cpp:49:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
49 | if (*it==-1) return mx(1, 0, n-1, 0, n-1);
| ~^~
horses.cpp:49:43: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
49 | if (*it==-1) return mx(1, 0, n-1, 0, n-1);
| ~^~
horses.cpp:49:27: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
49 | if (*it==-1) return mx(1, 0, n-1, 0, n-1);
| ~~^~~~~~~~~~~~~~~~~~~
horses.cpp:58:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
58 | ans = max(mx(1, 0, n-1, 0, *it-1), ans);
| ~^~
horses.cpp:64:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
64 | ans = max(mx(1, 0, n-1, *it, *prev(it) - 1) * cnt2, ans);
| ~^~
horses.cpp:70:12: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
70 | return ans;
| ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:77:14: warning: conversion from 'long long int' to 'std::set<int>::value_type' {aka 'int'} may change value [-Wconversion]
77 | s.insert(n);
| ^
horses.cpp:83:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
83 | build(1, 0, n-1);
| ~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:101:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
101 | update(1, 0, n-1, pos, val);
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2500 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2496 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
4540 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
2500 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
523 ms |
49588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4552 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
0 ms |
2492 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
2492 KB |
Output is correct |
21 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2408 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |