# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
640381 |
2022-09-14T12:40:25 Z |
piOOE |
Horses (IOI15_horses) |
C++17 |
|
460 ms |
47152 KB |
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
using ll = long long;
using i128 = __int128;
constexpr int MOD = 1e9 + 7;
int add(int a, int b) {
return a + b < MOD ? a + b : a + b - MOD;
}
int mul(int a, int b) {
return a * (long long) b % MOD;
}
int sub(int a, int b) {
return a >= b ? a - b : a - b + MOD;
}
int power(int a, int b) {
int ans = 1;
for (; b > 0; b >>= 1, a = mul(a, a)) if (b & 1) ans = mul(ans, a);
return ans;
}
int inv(int a) {
return power(a, MOD - 2);
}
struct segtreeY {
vector<int> t;
int sz = 1;
void init(vector<int> a) {
sz = 1;
while (sz < a.size()) sz <<= 1;
t.assign(sz << 1, 0);
for (int i = 0; i < a.size(); ++i) {
t[i + sz] = a[i];
}
for (int i = sz - 1; i > 0; --i) {
t[i] = max(t[i << 1], t[i << 1 | 1]);
}
}
void pull(int x) {
t[x] = max(t[x << 1], t[x << 1 | 1]);
}
void modify(int i, int val) {
modify(i, val, 1, 0, sz);
}
void modify(int i, int val, int x, int lx, int rx) {
if (lx + 1 == rx) {
t[x] = val;
return;
}
int mid = (lx + rx) >> 1;
if (i < mid) modify(i, val, x << 1, lx, mid);
else modify(i, val, x << 1 | 1, mid, rx);
pull(x);
}
int query(int l, int r) {
return query(l, r, 1, 0, sz);
}
int query(int l, int r, int x, int lx, int rx) {
if (l >= rx || lx >= r) return 0;
if (l <= lx && rx <= r) return t[x];
int mid = (lx + rx) >> 1;
return max(query(l, r, x << 1, lx, mid), query(l, r, x << 1 | 1, mid, rx));
}
};
int n;
vector<int> x, y;
int prodX = 1;
set<int> alive;
bool operator<(pair<i128, i128> a, pair<i128, i128> b) {
return a.first * b.second < a.second * b.first;
}
segtreeY st;
int answer() {
alive.insert(0);
if (alive.empty()) {
return st.t[1] % MOD;
}
auto it = alive.end();
pair<i128, i128> ans = {0, 1};
i128 prod = 1;
do {
it = prev(it);
pair<i128, i128> now = {st.query(*it, n), prod};
if (ans < now) {
ans = now;
}
prod *= x[*it];
now = {1e9, prod};
if (now < ans) {
break;
}
} while (it != alive.begin());
int val = mul(ans.first % MOD, inv(ans.second % MOD));
return mul(prodX, val);
}
int init(int N, int X[], int Y[]) {
n = N;
x.resize(n), y.resize(n);
for (int i = 0; i < n; ++i) {
x[i] = X[i], y[i] = Y[i];
if (x[i] != 1) {
prodX = mul(prodX, x[i]);
alive.insert(alive.end(), i);
}
}
st.init(y);
return answer();
}
int updateX(int pos, int val) {
prodX = mul(prodX, inv(x[pos]));
x[pos] = val;
prodX = mul(prodX, x[pos]);
if (val == 1) {
alive.erase(pos);
} else {
alive.insert(pos);
}
return answer();
}
int updateY(int pos, int val) {
y[pos] = val;
st.modify(pos, val);
return answer();
}
Compilation message
horses.cpp: In function 'int mul(int, int)':
horses.cpp:15:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
15 | return a * (long long) b % MOD;
| ~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In member function 'void segtreeY::init(std::vector<int>)':
horses.cpp:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | while (sz < a.size()) sz <<= 1;
| ~~~^~~~~~~~~~
horses.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i < a.size(); ++i) {
| ~~^~~~~~~~~~
horses.cpp: In function 'int answer()':
horses.cpp:114:51: warning: conversion from '__int128' to 'int' may change value [-Wconversion]
114 | int val = mul(ans.first % MOD, inv(ans.second % MOD));
| ~~~~~~~~~~~^~~~~
horses.cpp:114:29: warning: conversion from '__int128' to 'int' may change value [-Wconversion]
114 | int val = mul(ans.first % MOD, inv(ans.second % MOD));
| ~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
296 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
292 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
316 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
308 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
308 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
364 ms |
40520 KB |
Output is correct |
2 |
Correct |
234 ms |
45616 KB |
Output is correct |
3 |
Correct |
217 ms |
40392 KB |
Output is correct |
4 |
Correct |
230 ms |
44276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
216 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
308 KB |
Output is correct |
24 |
Correct |
1 ms |
312 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
308 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
308 KB |
Output is correct |
32 |
Correct |
2 ms |
312 KB |
Output is correct |
33 |
Correct |
37 ms |
18036 KB |
Output is correct |
34 |
Correct |
38 ms |
18112 KB |
Output is correct |
35 |
Correct |
114 ms |
46440 KB |
Output is correct |
36 |
Correct |
109 ms |
46428 KB |
Output is correct |
37 |
Correct |
69 ms |
16248 KB |
Output is correct |
38 |
Correct |
72 ms |
28896 KB |
Output is correct |
39 |
Correct |
28 ms |
16320 KB |
Output is correct |
40 |
Correct |
90 ms |
43524 KB |
Output is correct |
41 |
Correct |
44 ms |
16124 KB |
Output is correct |
42 |
Correct |
54 ms |
16204 KB |
Output is correct |
43 |
Correct |
78 ms |
43912 KB |
Output is correct |
44 |
Correct |
76 ms |
44012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
296 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
216 KB |
Output is correct |
18 |
Correct |
0 ms |
216 KB |
Output is correct |
19 |
Correct |
0 ms |
216 KB |
Output is correct |
20 |
Correct |
1 ms |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
216 KB |
Output is correct |
22 |
Correct |
0 ms |
216 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
316 KB |
Output is correct |
25 |
Correct |
2 ms |
316 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
308 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
357 ms |
40392 KB |
Output is correct |
34 |
Correct |
233 ms |
45528 KB |
Output is correct |
35 |
Correct |
228 ms |
40388 KB |
Output is correct |
36 |
Correct |
228 ms |
44344 KB |
Output is correct |
37 |
Correct |
38 ms |
18104 KB |
Output is correct |
38 |
Correct |
34 ms |
18036 KB |
Output is correct |
39 |
Correct |
111 ms |
46356 KB |
Output is correct |
40 |
Correct |
102 ms |
46524 KB |
Output is correct |
41 |
Correct |
68 ms |
16204 KB |
Output is correct |
42 |
Correct |
57 ms |
28864 KB |
Output is correct |
43 |
Correct |
29 ms |
16256 KB |
Output is correct |
44 |
Correct |
86 ms |
43496 KB |
Output is correct |
45 |
Correct |
43 ms |
16204 KB |
Output is correct |
46 |
Correct |
57 ms |
16236 KB |
Output is correct |
47 |
Correct |
81 ms |
44044 KB |
Output is correct |
48 |
Correct |
83 ms |
43940 KB |
Output is correct |
49 |
Correct |
148 ms |
19288 KB |
Output is correct |
50 |
Correct |
112 ms |
19364 KB |
Output is correct |
51 |
Correct |
220 ms |
47148 KB |
Output is correct |
52 |
Correct |
164 ms |
47152 KB |
Output is correct |
53 |
Correct |
460 ms |
17792 KB |
Output is correct |
54 |
Correct |
181 ms |
31192 KB |
Output is correct |
55 |
Correct |
106 ms |
16312 KB |
Output is correct |
56 |
Correct |
175 ms |
43592 KB |
Output is correct |
57 |
Correct |
253 ms |
16380 KB |
Output is correct |
58 |
Correct |
372 ms |
16564 KB |
Output is correct |
59 |
Correct |
83 ms |
44000 KB |
Output is correct |