# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
802379 |
2023-08-02T12:00:29 Z |
erray |
Horses (IOI15_horses) |
C++17 |
|
315 ms |
38456 KB |
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "/home/ioi/codes/ioi15_d2/debug.h"
#else
#define debug(...) void(37)
#endif
template<typename T>
vector<T> inverse_fuck(T* a, int N) {
vector<T> res(N);
for (int i = 0; i < N; ++i) {
res[i] = a[i];
}
return res;
}
struct SegTree {
vector<int> mx;
int n;
SegTree(int _n) : n(_n) {
mx.resize(2 * n + 1);
}
SegTree() { }
int get(int l) {
l += n;
int r = 2 * n;
int res = 0;
while (l < r) {
if (l & 1) {
res = max(res, mx[l++]);
}
if (r & 1) {
res = max(res, mx[--r]);
}
l >>= 1, r >>= 1;
}
return res;
}
void modify(int x, int v) {
mx[x += n] = v;
while (x > 1) {
mx[x >> 1] = max(mx[x], mx[x ^ 1]);
x >>= 1;
}
}
};
constexpr int md = int(1e9) + 7;
struct Mint {
int val = 0;
Mint() { }
template<typename T>
Mint(T v) {
val = int(v % md);
if (val < 0) {
val += md;
}
}
int& operator()() { return val; }
Mint& operator+=(Mint x) {
if ((val += x.val) > md) {
val -= md;
}
return *this;
}
Mint& operator*=(Mint x) {
val = int(1LL * val * x.val % md);
return *this;
}
Mint power(Mint x, int p) {
Mint res = 1;
while (p > 0) {
if (p & 1) {
res *= x;
}
x *= x;
p >>= 1;
}
return res;
}
Mint& operator/=(Mint x) {
//debug(x, power(x, md - 2));
return *this *= power(x, md - 2);
}
};
Mint operator+(Mint x, Mint y) {
return x += y;
}
Mint operator*(Mint x, Mint y) {
return x *= y;
}
Mint operator/(Mint x, Mint y) {
return x /= y;
}
string to_string(Mint x) {
return to_string(x());
}
int N;
set<int> act;
SegTree st;
vector<int> X, Y;
vector<Mint> inv;
Mint tot = 1;
int Calc() {
//assert(!act.empty());
act.insert(0);
auto it = act.end();
long long mul = 1;
vector<int> t;
while (it != act.begin() && mul < int(1e9)) {
it = prev(it);
mul *= X[*it];
t.push_back(*it);
}
debug(t);
reverse(t.begin(), t.end());
long long mx = -1;
mul = 1;
Mint pref = tot;
bool first = true;
for (auto i : t) {
if (!first) {
pref *= inv[i];
mul *= X[i];
}
mx = max(mx, mul * st.get(i));
first = false;
}
return (pref * mx)();
}
int init(int __N, int __X[], int __Y[]) {
N = __N;
X = inverse_fuck(__X, N);
Y = inverse_fuck(__Y, N);
inv.resize(N);
for (int i = 0; i < N; ++i) {
inv[i] = Mint(1) / X[i];
tot *= X[i];
if (X[i] != 1) {
act.insert(i);
}
}
st = SegTree(N);
for (int i = 0; i < N; ++i) {
st.modify(i, Y[i]);
}
debug(X, inv, tot);
return Calc();
}
int updateX(int pos, int val) {
if (X[pos] != val) {
if (X[pos] == 1) { //replace set with sth else if it get's tle
act.insert(pos);
} else if(val == 1) {
act.erase(pos);
}
tot *= inv[pos] * val;
X[pos] = val;
inv[pos] = Mint(1) / X[pos];
}
return Calc();
}
int updateY(int pos, int val) {
st.modify(pos, val);
return Calc();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
276 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 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 |
# |
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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
315 ms |
38364 KB |
Output is correct |
2 |
Correct |
280 ms |
38456 KB |
Output is correct |
3 |
Correct |
252 ms |
38388 KB |
Output is correct |
4 |
Correct |
266 ms |
38384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 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 |
212 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 |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 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 |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
108 ms |
14188 KB |
Output is correct |
34 |
Correct |
111 ms |
14284 KB |
Output is correct |
35 |
Correct |
228 ms |
37488 KB |
Output is correct |
36 |
Correct |
229 ms |
37596 KB |
Output is correct |
37 |
Correct |
106 ms |
14232 KB |
Output is correct |
38 |
Correct |
143 ms |
26068 KB |
Output is correct |
39 |
Correct |
89 ms |
13944 KB |
Output is correct |
40 |
Correct |
243 ms |
37600 KB |
Output is correct |
41 |
Correct |
104 ms |
14112 KB |
Output is correct |
42 |
Correct |
103 ms |
14004 KB |
Output is correct |
43 |
Correct |
222 ms |
37484 KB |
Output is correct |
44 |
Correct |
230 ms |
37420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
0 ms |
212 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 |
0 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 |
0 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 |
212 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 |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 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 |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
260 ms |
38428 KB |
Output is correct |
34 |
Correct |
281 ms |
38452 KB |
Output is correct |
35 |
Correct |
223 ms |
38444 KB |
Output is correct |
36 |
Correct |
272 ms |
38384 KB |
Output is correct |
37 |
Correct |
100 ms |
14136 KB |
Output is correct |
38 |
Correct |
102 ms |
14136 KB |
Output is correct |
39 |
Correct |
235 ms |
37524 KB |
Output is correct |
40 |
Correct |
224 ms |
37564 KB |
Output is correct |
41 |
Correct |
98 ms |
14152 KB |
Output is correct |
42 |
Correct |
142 ms |
26040 KB |
Output is correct |
43 |
Correct |
95 ms |
13924 KB |
Output is correct |
44 |
Correct |
221 ms |
37568 KB |
Output is correct |
45 |
Correct |
92 ms |
13996 KB |
Output is correct |
46 |
Correct |
96 ms |
14012 KB |
Output is correct |
47 |
Correct |
202 ms |
37480 KB |
Output is correct |
48 |
Correct |
207 ms |
37388 KB |
Output is correct |
49 |
Correct |
137 ms |
16108 KB |
Output is correct |
50 |
Correct |
136 ms |
16036 KB |
Output is correct |
51 |
Correct |
268 ms |
38436 KB |
Output is correct |
52 |
Correct |
262 ms |
38392 KB |
Output is correct |
53 |
Correct |
234 ms |
15948 KB |
Output is correct |
54 |
Correct |
193 ms |
29088 KB |
Output is correct |
55 |
Correct |
126 ms |
14200 KB |
Output is correct |
56 |
Correct |
266 ms |
38388 KB |
Output is correct |
57 |
Correct |
152 ms |
14956 KB |
Output is correct |
58 |
Correct |
166 ms |
14980 KB |
Output is correct |
59 |
Correct |
210 ms |
37448 KB |
Output is correct |