#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
using ll = long long;
const ll MOD = ((ll) 1e9) + 7;
ll n;
vector < ll > ma;
vector < ll > bit;
int sts = 1;
vector < ll > mst;
set < ll > cs;
ll
binpow (ll a, ll b)
{
ll ans = 1, ac = a;
while (b)
{
if (b % 2) (ans *= ac) %= MOD;
b /= 2;
if (b) (ac *= a) %= MOD;
}
return ans;
}
ll
bitp (ll x)
{
ll ans = 1;
while (x >= 0)
{
(ans *= bit[x]) %= MOD;
x -= (x + 1) & -(x + 1);
}
return ans;
}
ll
bitr (ll l, ll r)
{
ll ans = bitp (r);
if (l) (ans *= binpow (bitp (l - 1), MOD - 2)) %= MOD;
return ans;
}
ll
stm (ll l, ll r)
{
l += sts, r += sts;
ll mx = -1;
while (l <= r)
{
if (l % 2 == 1) mx = max (mx, mst[l++]);
if (r % 2 == 0) mx = max (mx, mst[r--]);
l /= 2, r /= 2;
}
return mx;
}
int
calc ()
{
auto it = cs.end (), pit = prev (it);
ll vl = 0;
while (vl < MOD)
{
--it, --pit;
vl = max (vl, mst[sts + *it]);
vl *= ma[*it];
if (*it && *pit + 1 <= *it - 1)
vl = max (vl, stm (*pit + 1, *it - 1));
if (!*it) break;
}
vl %= MOD;
if (*it)
(vl *= bitp (*it - 1)) %= MOD;
return vl;
}
int init(int N, int x[], int y[]) {
n = N;
ma.resize (n);
bit.resize (n);
while (sts < n) sts *= 2;
mst.resize (sts * 2);
for (int i = 0; i < n; ++i)
{
if (x[i] > 1) cs.insert (i);
ma[i] = x[i];
mst[sts + i] = y[i];
bit[i] = x[i] * (i ? bitr (i - ((i + 1) & -(i + 1)) + 1, i - 1) : 1ll);
}
for (int i = sts - 1; i > 0; --i) mst[i] = max (mst[i * 2], mst[i * 2 + 1]);
cs.insert (0);
cs.insert (n - 1);
return calc ();
}
int updateX(int pos, int val) {
cs.erase (pos);
if (val > 1) cs.insert (pos);
ma[pos] = val;
bit[pos] = val * (val ? bitr (pos - ((pos + 1) & -(pos + 1)) + 1, pos - 1) : 1ll);
cs.insert (0);
cs.insert (n - 1);
return calc ();
}
int updateY(int pos, int val) {
int i = sts + pos;
mst[i] = val;
for (i /= 2; i > 0; i /= 2) mst[i] = max (mst[i * 2], mst[i * 2 + 1]);
return calc ();
}
Compilation message
horses.cpp: In function 'int calc()':
horses.cpp:79:10: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
79 | return vl;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
428 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
440 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
436 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
432 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
436 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Incorrect |
0 ms |
432 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
242 ms |
46848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
436 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Incorrect |
0 ms |
436 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |