#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
set<int> xge2;
const int MOD = 1e9 + 7;
const int MX = 5e5 + 5;
struct ST
{
int size;
vector<ll> mul, mx;
ST(int _size) : size(_size), mul(2 * _size, 1), mx(2 * _size) {}
ll qmx(int l, int r)
{
ll ret = 0;
for (l += size, r += size; l < r; l /= 2, r /= 2)
{
if (l & 1)
ret = max(ret, mx[l++]);
if (r & 1)
ret = max(ret, mx[--r]);
}
return ret;
}
ll qmul(int l, int r)
{
ll ret = 1;
for (l += size, r += size; l < r; l /= 2, r /= 2)
{
if (l & 1)
ret = (ret * mul[l++]) % MOD;
if (r & 1)
ret = (ret * mul[--r]) % MOD;
}
return ret;
}
void umx(int i, ll v)
{
mx[i += size] = v;
for (i /= 2; i; i /= 2)
mx[i] = max(mx[2 * i], mx[2 * i + 1]);
}
void umul(int i, ll v)
{
mul[i += size] = v;
for (i /= 2; i; i /= 2)
mul[i] = (mul[2 * i] * mul[2 * i + 1]) % MOD;
}
} st(2 * MX);
int n, x[MX], y[MX];
int ans()
{
if (xge2.empty())
{
return st.qmx(0, n);
}
ll s = 1;
int hi = n;
auto it = xge2.rbegin();
vector<ll> a, b, c;
while (it != xge2.rend())
{
int v = *it;
a.push_back(v);
b.push_back(s);
c.push_back(st.qmx(v, hi));
if (s > MOD)
break;
s *= x[v];
hi = v;
it++;
}
pair<ll, int> mx_ans = {-1, -1};
for (int i = 0; i < (int)a.size(); i++)
{
mx_ans = max(mx_ans, {s / b[i] * c[i], i});
}
ll ans = 0;
ans = (st.qmul(0, a[mx_ans.second] + 1) * c[mx_ans.second]) % MOD;
return ans;
}
int init(int N, int X[], int Y[])
{
n = N;
x[N] = 1;
for (int i = 0; i < N; ++i)
{
if (X[i] >= 2)
xge2.insert(i);
st.umul(i, X[i]);
st.umx(i, Y[i]);
}
copy(X, X + N, x);
copy(Y, Y + N, y);
return ans();
}
int updateX(int pos, int val)
{
if (val == 1 && xge2.find(pos) != xge2.end())
xge2.erase(pos);
else
xge2.insert(pos);
st.umul(pos, x[pos] = val);
return ans();
}
int updateY(int pos, int val)
{
st.umx(pos, y[pos] = val);
return ans();
}
Compilation message
horses.cpp: In function 'int ans()':
horses.cpp:59:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
59 | return st.qmx(0, n);
| ~~~~~~^~~~~~
horses.cpp:83:37: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
83 | ans = (st.qmul(0, a[mx_ans.second] + 1) * c[mx_ans.second]) % MOD;
horses.cpp:84:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
84 | return ans;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
31524 KB |
Output is correct |
2 |
Correct |
17 ms |
31588 KB |
Output is correct |
3 |
Correct |
14 ms |
31564 KB |
Output is correct |
4 |
Correct |
15 ms |
31632 KB |
Output is correct |
5 |
Correct |
14 ms |
31572 KB |
Output is correct |
6 |
Correct |
15 ms |
31564 KB |
Output is correct |
7 |
Correct |
16 ms |
31636 KB |
Output is correct |
8 |
Correct |
14 ms |
31644 KB |
Output is correct |
9 |
Correct |
14 ms |
31592 KB |
Output is correct |
10 |
Correct |
14 ms |
31564 KB |
Output is correct |
11 |
Correct |
14 ms |
31636 KB |
Output is correct |
12 |
Correct |
14 ms |
31648 KB |
Output is correct |
13 |
Correct |
17 ms |
31568 KB |
Output is correct |
14 |
Correct |
18 ms |
31628 KB |
Output is correct |
15 |
Correct |
16 ms |
31612 KB |
Output is correct |
16 |
Correct |
20 ms |
31632 KB |
Output is correct |
17 |
Correct |
21 ms |
31628 KB |
Output is correct |
18 |
Correct |
19 ms |
31528 KB |
Output is correct |
19 |
Correct |
18 ms |
31520 KB |
Output is correct |
20 |
Correct |
18 ms |
31632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31632 KB |
Output is correct |
2 |
Correct |
16 ms |
31632 KB |
Output is correct |
3 |
Correct |
15 ms |
31612 KB |
Output is correct |
4 |
Correct |
18 ms |
31536 KB |
Output is correct |
5 |
Correct |
15 ms |
31596 KB |
Output is correct |
6 |
Correct |
14 ms |
31632 KB |
Output is correct |
7 |
Correct |
18 ms |
31640 KB |
Output is correct |
8 |
Correct |
15 ms |
31540 KB |
Output is correct |
9 |
Correct |
16 ms |
31636 KB |
Output is correct |
10 |
Correct |
17 ms |
31580 KB |
Output is correct |
11 |
Correct |
18 ms |
31564 KB |
Output is correct |
12 |
Correct |
14 ms |
31612 KB |
Output is correct |
13 |
Correct |
15 ms |
31564 KB |
Output is correct |
14 |
Correct |
14 ms |
31632 KB |
Output is correct |
15 |
Correct |
17 ms |
31640 KB |
Output is correct |
16 |
Correct |
19 ms |
31540 KB |
Output is correct |
17 |
Correct |
17 ms |
31572 KB |
Output is correct |
18 |
Correct |
16 ms |
31536 KB |
Output is correct |
19 |
Correct |
15 ms |
31564 KB |
Output is correct |
20 |
Correct |
17 ms |
31564 KB |
Output is correct |
21 |
Correct |
15 ms |
31620 KB |
Output is correct |
22 |
Correct |
15 ms |
31564 KB |
Output is correct |
23 |
Incorrect |
19 ms |
31616 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
458 ms |
64660 KB |
Output is correct |
2 |
Incorrect |
526 ms |
64252 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
31564 KB |
Output is correct |
2 |
Correct |
16 ms |
31516 KB |
Output is correct |
3 |
Correct |
17 ms |
31620 KB |
Output is correct |
4 |
Correct |
15 ms |
31624 KB |
Output is correct |
5 |
Correct |
17 ms |
31616 KB |
Output is correct |
6 |
Correct |
17 ms |
31564 KB |
Output is correct |
7 |
Correct |
16 ms |
31632 KB |
Output is correct |
8 |
Correct |
17 ms |
31556 KB |
Output is correct |
9 |
Correct |
18 ms |
31616 KB |
Output is correct |
10 |
Correct |
17 ms |
31612 KB |
Output is correct |
11 |
Correct |
16 ms |
31564 KB |
Output is correct |
12 |
Correct |
17 ms |
31532 KB |
Output is correct |
13 |
Correct |
16 ms |
31552 KB |
Output is correct |
14 |
Correct |
16 ms |
31564 KB |
Output is correct |
15 |
Correct |
18 ms |
31564 KB |
Output is correct |
16 |
Correct |
16 ms |
31568 KB |
Output is correct |
17 |
Correct |
19 ms |
31560 KB |
Output is correct |
18 |
Correct |
15 ms |
31564 KB |
Output is correct |
19 |
Correct |
17 ms |
31628 KB |
Output is correct |
20 |
Correct |
16 ms |
31548 KB |
Output is correct |
21 |
Correct |
18 ms |
31628 KB |
Output is correct |
22 |
Correct |
18 ms |
31612 KB |
Output is correct |
23 |
Incorrect |
17 ms |
31612 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31564 KB |
Output is correct |
2 |
Correct |
17 ms |
31604 KB |
Output is correct |
3 |
Correct |
16 ms |
31564 KB |
Output is correct |
4 |
Correct |
16 ms |
31636 KB |
Output is correct |
5 |
Correct |
16 ms |
31552 KB |
Output is correct |
6 |
Correct |
17 ms |
31588 KB |
Output is correct |
7 |
Correct |
16 ms |
31624 KB |
Output is correct |
8 |
Correct |
16 ms |
31528 KB |
Output is correct |
9 |
Correct |
23 ms |
31544 KB |
Output is correct |
10 |
Correct |
18 ms |
31564 KB |
Output is correct |
11 |
Correct |
25 ms |
31520 KB |
Output is correct |
12 |
Correct |
18 ms |
31632 KB |
Output is correct |
13 |
Correct |
16 ms |
31596 KB |
Output is correct |
14 |
Correct |
15 ms |
31632 KB |
Output is correct |
15 |
Correct |
15 ms |
31564 KB |
Output is correct |
16 |
Correct |
17 ms |
31540 KB |
Output is correct |
17 |
Correct |
16 ms |
31552 KB |
Output is correct |
18 |
Correct |
16 ms |
31604 KB |
Output is correct |
19 |
Correct |
18 ms |
31632 KB |
Output is correct |
20 |
Correct |
15 ms |
31564 KB |
Output is correct |
21 |
Correct |
16 ms |
31640 KB |
Output is correct |
22 |
Correct |
15 ms |
31628 KB |
Output is correct |
23 |
Incorrect |
17 ms |
31664 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |