# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
825212 |
2023-08-14T15:42:32 Z |
Nelt |
Horses (IOI15_horses) |
C++17 |
|
249 ms |
60820 KB |
#include "horses.h"
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/* DEFINES */
#define S second
#define F first
#define ll long long
#define ull unsigned long long
#define ld long double
#define npos ULLONG_MAX
#define INF LLONG_MAX
#define vv(a) vector<a>
#define pp(a, b) pair<a, b>
#define pq(a) priority_queue<a>
#define qq(a) queue<a>
#define ss(a) set<a>
#define mm(a, b) map<a, b>
#define ump(a, b) unordered_map<a, b>
#define ANDROID \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define elif else if
#define endl "\n"
#define allc(a) begin(a), end(a)
#define all(a) a, a + sizeof(a) / sizeof(a[0])
#define pb push_back
#define logi(a) __lg(a)
#define sqrt(a) sqrtl(a)
#define mpr make_pair
#define ins insert
using namespace std;
using namespace __gnu_pbds;
using namespace __cxx11;
typedef char chr;
typedef basic_string<chr> str;
template <typename T, typename key = less<T>>
using ordered_set = tree<T, null_type, key, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 5e5 + 5, mod = 1e9 + 7;
ll a[N], b[N], n;
ll t[N];
ll binpow(ll n, ll p)
{
ll ans = 1;
n %= mod;
while (p)
{
ans = (p & 1 ? (ans * n) % mod : ans);
n = (n * n) % mod;
p >>= 1;
}
return ans;
}
ll inv(ll x)
{
return binpow(x, mod - 2);
}
ll product(ll i)
{
ll res = 1;
for (; i > 0; i = (i & (i + 1)) - 1)
res = res * t[i] % mod;
return res;
}
void upd(ll i, ll d)
{
for (; i <= n; i = (i | (i + 1)))
t[i] = t[i] * d % mod;
}
struct SegTree
{
ll n;
vv(ll) st;
SegTree(ll sz = 0, bool input = false)
{
n = sz;
st.resize((n + 1) << 1, 0);
}
void set(ll i, ll val)
{
st[i + n - 1] = val;
}
void build()
{
for (ll i = n - 1; i >= 1; i--)
st[i] = max(st[i << 1], st[i << 1 | 1]);
}
void modify(ll p, ll val)
{
for (st[p += n - 1] = val; p > 1; p >>= 1)
st[p >> 1] = max(st[p], st[p ^ 1]);
}
ll query(ll l, ll r)
{
ll ans = 0;
for (l += n - 1, r += n; l < r; l >>= 1, r >>= 1)
{
if (l & 1)
ans = max(ans, st[l++]);
if (r & 1)
ans = max(ans, st[--r]);
}
return ans;
}
} st(N);
ss(ll) s;
ll solve()
{
__int128 prod = 1;
auto it = --s.end();
while (it != s.begin() and prod * a[*it] <= 1e9)
prod *= a[*it], it--;
// cout << s.size() << endl;
if (prod * a[*it] <= 1e9)
{
__int128 ans = st.query(1, n), one = 1;
for (; *it != n + 1; it++)
ans = max(ans, one * product(*it) * st.query(*it, n));
return ans % mod;
}
prod = 1;
__int128 ans = 1, start = *it;
for (; *it != n + 1; it++)
prod *= a[*it], ans = max(ans, prod * st.query(*it, n));
return ans % mod * product(start - 1) % mod;
}
int init(int N, int X[], int Y[])
{
n = N;
for (ll i = 0; i < n; i++)
a[i + 1] = X[i], b[i + 1] = Y[i], t[i + 1] = 1;
for (ll i = 1; i <= n; i++)
{
if (a[i] > 1)
s.ins(i);
st.set(i, b[i]);
upd(i, a[i]);
}
st.build();
a[n + 1] = b[n + 1] = 1;
s.ins(n + 1);
return solve();
}
int updateX(int pos, int val)
{
pos++;
upd(pos, inv(a[pos]) * val % mod);
a[pos] = val;
if (a[pos] > 1)
s.ins(pos);
elif (s.count(pos))
s.erase(pos);
return solve();
}
int updateY(int pos, int val)
{
pos++;
st.modify(pos, b[pos] = val);
return solve();
}
Compilation message
horses.cpp: In function 'long long int binpow(long long int, long long int)':
horses.cpp:48:14: warning: declaration of 'n' shadows a global declaration [-Wshadow]
48 | ll binpow(ll n, ll p)
| ^
horses.cpp:46:16: note: shadowed declaration is here
46 | ll a[N], b[N], n;
| ^
horses.cpp: In constructor 'SegTree::SegTree(long long int, bool)':
horses.cpp:80:29: warning: unused parameter 'input' [-Wunused-parameter]
80 | SegTree(ll sz = 0, bool input = false)
| ~~~~~^~~~~~~~~~~~~
horses.cpp: In function 'long long int solve()':
horses.cpp:117:37: warning: conversion from '__int128' to 'double' may change value [-Wconversion]
117 | while (it != s.begin() and prod * a[*it] <= 1e9)
| ~~~~~^~~~~~~~
horses.cpp:120:14: warning: conversion from '__int128' to 'double' may change value [-Wconversion]
120 | if (prod * a[*it] <= 1e9)
| ~~~~~^~~~~~~~
horses.cpp:125:20: warning: conversion from '__int128' to 'long long int' may change value [-Wconversion]
125 | return ans % mod;
| ~~~~^~~~~
horses.cpp:131:38: warning: conversion from '__int128' to 'long long int' may change value [-Wconversion]
131 | return ans % mod * product(start - 1) % mod;
| ~~~~~~^~~
horses.cpp:131:43: warning: conversion from '__int128' to 'long long int' may change value [-Wconversion]
131 | return ans % mod * product(start - 1) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:133:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
133 | int init(int N, int X[], int Y[])
| ~~~~^
horses.cpp:45:10: note: shadowed declaration is here
45 | const ll N = 5e5 + 5, mod = 1e9 + 7;
| ^
horses.cpp:148:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
148 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:160:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
160 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:166:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
166 | return solve();
| ~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
5 ms |
8148 KB |
Output is correct |
6 |
Correct |
4 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
4 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
3 ms |
8148 KB |
Output is correct |
11 |
Correct |
3 ms |
8068 KB |
Output is correct |
12 |
Correct |
3 ms |
8092 KB |
Output is correct |
13 |
Correct |
4 ms |
8148 KB |
Output is correct |
14 |
Correct |
3 ms |
8148 KB |
Output is correct |
15 |
Correct |
3 ms |
8148 KB |
Output is correct |
16 |
Correct |
3 ms |
8148 KB |
Output is correct |
17 |
Correct |
4 ms |
8148 KB |
Output is correct |
18 |
Correct |
3 ms |
8052 KB |
Output is correct |
19 |
Correct |
3 ms |
8148 KB |
Output is correct |
20 |
Correct |
3 ms |
8100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
4 ms |
8160 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
3 ms |
8148 KB |
Output is correct |
6 |
Correct |
4 ms |
8148 KB |
Output is correct |
7 |
Correct |
3 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8124 KB |
Output is correct |
9 |
Correct |
3 ms |
8148 KB |
Output is correct |
10 |
Correct |
3 ms |
8148 KB |
Output is correct |
11 |
Correct |
4 ms |
8112 KB |
Output is correct |
12 |
Correct |
4 ms |
8148 KB |
Output is correct |
13 |
Correct |
4 ms |
8148 KB |
Output is correct |
14 |
Correct |
3 ms |
8148 KB |
Output is correct |
15 |
Correct |
3 ms |
8148 KB |
Output is correct |
16 |
Correct |
3 ms |
8148 KB |
Output is correct |
17 |
Correct |
3 ms |
8148 KB |
Output is correct |
18 |
Correct |
4 ms |
8148 KB |
Output is correct |
19 |
Correct |
3 ms |
8100 KB |
Output is correct |
20 |
Correct |
4 ms |
8068 KB |
Output is correct |
21 |
Correct |
4 ms |
8148 KB |
Output is correct |
22 |
Correct |
3 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8196 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
4 ms |
8148 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
27 |
Correct |
5 ms |
8148 KB |
Output is correct |
28 |
Correct |
4 ms |
8268 KB |
Output is correct |
29 |
Correct |
4 ms |
8160 KB |
Output is correct |
30 |
Correct |
5 ms |
8268 KB |
Output is correct |
31 |
Correct |
4 ms |
8148 KB |
Output is correct |
32 |
Correct |
5 ms |
8172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
48188 KB |
Output is correct |
2 |
Correct |
226 ms |
57420 KB |
Output is correct |
3 |
Correct |
193 ms |
48168 KB |
Output is correct |
4 |
Correct |
245 ms |
48160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8148 KB |
Output is correct |
2 |
Correct |
3 ms |
8148 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
4 ms |
8148 KB |
Output is correct |
6 |
Correct |
3 ms |
8148 KB |
Output is correct |
7 |
Correct |
3 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
4 ms |
8080 KB |
Output is correct |
10 |
Correct |
3 ms |
8148 KB |
Output is correct |
11 |
Correct |
4 ms |
8148 KB |
Output is correct |
12 |
Correct |
3 ms |
8148 KB |
Output is correct |
13 |
Correct |
3 ms |
8148 KB |
Output is correct |
14 |
Correct |
3 ms |
8148 KB |
Output is correct |
15 |
Correct |
3 ms |
8084 KB |
Output is correct |
16 |
Correct |
4 ms |
8148 KB |
Output is correct |
17 |
Correct |
4 ms |
8148 KB |
Output is correct |
18 |
Correct |
3 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8148 KB |
Output is correct |
20 |
Correct |
3 ms |
8148 KB |
Output is correct |
21 |
Correct |
3 ms |
8148 KB |
Output is correct |
22 |
Correct |
3 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8148 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
4 ms |
8148 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
27 |
Correct |
4 ms |
8148 KB |
Output is correct |
28 |
Correct |
4 ms |
8276 KB |
Output is correct |
29 |
Correct |
4 ms |
8148 KB |
Output is correct |
30 |
Correct |
5 ms |
8276 KB |
Output is correct |
31 |
Correct |
4 ms |
8148 KB |
Output is correct |
32 |
Correct |
5 ms |
8148 KB |
Output is correct |
33 |
Correct |
41 ms |
27872 KB |
Output is correct |
34 |
Correct |
41 ms |
27852 KB |
Output is correct |
35 |
Correct |
144 ms |
58208 KB |
Output is correct |
36 |
Correct |
143 ms |
58144 KB |
Output is correct |
37 |
Correct |
38 ms |
26092 KB |
Output is correct |
38 |
Correct |
75 ms |
38808 KB |
Output is correct |
39 |
Correct |
30 ms |
25804 KB |
Output is correct |
40 |
Correct |
128 ms |
53196 KB |
Output is correct |
41 |
Correct |
35 ms |
25892 KB |
Output is correct |
42 |
Correct |
37 ms |
25888 KB |
Output is correct |
43 |
Correct |
123 ms |
53588 KB |
Output is correct |
44 |
Correct |
124 ms |
53604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8148 KB |
Output is correct |
2 |
Correct |
3 ms |
8148 KB |
Output is correct |
3 |
Correct |
3 ms |
8148 KB |
Output is correct |
4 |
Correct |
3 ms |
8148 KB |
Output is correct |
5 |
Correct |
3 ms |
8148 KB |
Output is correct |
6 |
Correct |
4 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8164 KB |
Output is correct |
9 |
Correct |
3 ms |
8148 KB |
Output is correct |
10 |
Correct |
3 ms |
8148 KB |
Output is correct |
11 |
Correct |
3 ms |
8148 KB |
Output is correct |
12 |
Correct |
3 ms |
8148 KB |
Output is correct |
13 |
Correct |
3 ms |
8148 KB |
Output is correct |
14 |
Correct |
3 ms |
8148 KB |
Output is correct |
15 |
Correct |
3 ms |
8148 KB |
Output is correct |
16 |
Correct |
3 ms |
8148 KB |
Output is correct |
17 |
Correct |
3 ms |
8148 KB |
Output is correct |
18 |
Correct |
3 ms |
8148 KB |
Output is correct |
19 |
Correct |
3 ms |
8056 KB |
Output is correct |
20 |
Correct |
4 ms |
8148 KB |
Output is correct |
21 |
Correct |
3 ms |
8148 KB |
Output is correct |
22 |
Correct |
3 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8148 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
4 ms |
8248 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
27 |
Correct |
5 ms |
8148 KB |
Output is correct |
28 |
Correct |
4 ms |
8276 KB |
Output is correct |
29 |
Correct |
4 ms |
8148 KB |
Output is correct |
30 |
Correct |
5 ms |
8156 KB |
Output is correct |
31 |
Correct |
4 ms |
8164 KB |
Output is correct |
32 |
Correct |
4 ms |
8164 KB |
Output is correct |
33 |
Correct |
173 ms |
51972 KB |
Output is correct |
34 |
Correct |
229 ms |
60820 KB |
Output is correct |
35 |
Correct |
196 ms |
52044 KB |
Output is correct |
36 |
Correct |
249 ms |
55832 KB |
Output is correct |
37 |
Correct |
40 ms |
27888 KB |
Output is correct |
38 |
Correct |
43 ms |
27832 KB |
Output is correct |
39 |
Correct |
139 ms |
58128 KB |
Output is correct |
40 |
Correct |
137 ms |
58080 KB |
Output is correct |
41 |
Correct |
39 ms |
26084 KB |
Output is correct |
42 |
Correct |
74 ms |
38812 KB |
Output is correct |
43 |
Correct |
30 ms |
25804 KB |
Output is correct |
44 |
Correct |
126 ms |
53328 KB |
Output is correct |
45 |
Correct |
34 ms |
25900 KB |
Output is correct |
46 |
Correct |
37 ms |
25932 KB |
Output is correct |
47 |
Correct |
120 ms |
53592 KB |
Output is correct |
48 |
Correct |
135 ms |
53548 KB |
Output is correct |
49 |
Correct |
92 ms |
30920 KB |
Output is correct |
50 |
Correct |
90 ms |
30904 KB |
Output is correct |
51 |
Correct |
180 ms |
60032 KB |
Output is correct |
52 |
Correct |
190 ms |
59508 KB |
Output is correct |
53 |
Correct |
145 ms |
29172 KB |
Output is correct |
54 |
Correct |
132 ms |
42760 KB |
Output is correct |
55 |
Correct |
72 ms |
26904 KB |
Output is correct |
56 |
Correct |
186 ms |
55120 KB |
Output is correct |
57 |
Correct |
119 ms |
27452 KB |
Output is correct |
58 |
Correct |
145 ms |
28056 KB |
Output is correct |
59 |
Correct |
123 ms |
53628 KB |
Output is correct |