# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
719539 |
2023-04-06T09:24:55 Z |
thimote75 |
Horses (IOI15_horses) |
C++14 |
|
378 ms |
74824 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define num long long
#define inf 1e9
const num MOD = 1e9 + 7;
vector<num> X;
vector<num> Y;
struct SGD {
ld mx_ls = - inf;
ld se_ls = - inf;
num mx_pv = 0;
num se_pv = 0;
void merge (SGD &l, SGD &r) {
se_ls = l.se_ls + r.se_ls;
se_pv = (l.se_pv * r.se_pv) % MOD;
mx_ls = max(l.mx_ls, r.mx_ls + l.se_ls);
if (mx_ls == l.mx_ls) mx_pv = l.mx_pv;
else mx_pv = (l.se_pv * r.mx_pv) % MOD;
}
};
struct SegTree {
int size, start, height;
vector<SGD> tree;
SegTree (int _size) {
size = _size;
height = ceil(log2(size));
start = 1 << height;
tree.resize(start << 1);
}
num query () {
return tree[1].mx_pv;
}
void _update (int index) {
if (index == 0) return ;
if (index < start) {
int n0 = index << 1;
int n1 = n0 + 1;
tree[index].merge(tree[n0], tree[n1]);
}
_update(index >> 1);
}
void update (int pos, num x, num y) {
pos += start;
tree[pos].se_ls = log((ld) x);
tree[pos].mx_ls = log((ld) x) + log((ld) y);
tree[pos].se_pv = x;
tree[pos].mx_pv = (x * y) % MOD;
_update(pos);
}
void show () {
for (int h = 0; h <= height; h ++) {
int s = 1 << h;
for (int i = 0; i < s; i ++) {
cout << tree[i + s].mx_pv << ":" << tree[i + s].se_pv << "/e" << tree[i + s].mx_ls << ":e" << tree[i + s].se_ls << " ";
}
cout << endl;
}
}
};
SegTree tree(1);
int compute () {
return max(1, (int) tree.query());
}
int init(int N, int _X[], int _Y[]) {
X.resize(N);
Y.resize(N);
tree = SegTree(N);
for (int i = 0; i < N; i ++) {
X [i] = _X[i];
Y [i] = _Y[i];
tree.update(i, X[i], Y[i]);
}
return compute();
}
int updateX(int i, int val) {
X [i] = val;
tree.update(i, X[i], Y[i]);
return compute();
}
int updateY(int i, int val) {
Y [i] = val;
tree.update(i, X[i], Y[i]);
return compute();
}
Compilation message
horses.cpp: In constructor 'SegTree::SegTree(int)':
horses.cpp:39:16: warning: conversion from 'double' to 'int' may change value [-Wfloat-conversion]
39 | height = ceil(log2(size));
| ~~~~^~~~~~~~~~~~
# |
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 |
1 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 |
1 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 |
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 |
292 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 |
1 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 |
0 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 |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
440 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 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 |
304 KB |
Output is correct |
30 |
Correct |
2 ms |
436 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
336 ms |
62192 KB |
Output is correct |
2 |
Correct |
371 ms |
62240 KB |
Output is correct |
3 |
Correct |
368 ms |
66020 KB |
Output is correct |
4 |
Correct |
362 ms |
69876 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 |
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 |
1 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 |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 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 |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
436 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 |
436 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
271 ms |
61420 KB |
Output is correct |
34 |
Correct |
264 ms |
65228 KB |
Output is correct |
35 |
Correct |
292 ms |
72244 KB |
Output is correct |
36 |
Correct |
291 ms |
72188 KB |
Output is correct |
37 |
Correct |
254 ms |
63396 KB |
Output is correct |
38 |
Correct |
272 ms |
64372 KB |
Output is correct |
39 |
Correct |
247 ms |
63356 KB |
Output is correct |
40 |
Correct |
286 ms |
67208 KB |
Output is correct |
41 |
Correct |
253 ms |
63348 KB |
Output is correct |
42 |
Correct |
251 ms |
63472 KB |
Output is correct |
43 |
Correct |
284 ms |
67624 KB |
Output is correct |
44 |
Correct |
273 ms |
67672 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 |
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 |
0 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 |
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 |
2 ms |
440 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 |
440 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 |
436 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
436 KB |
Output is correct |
33 |
Correct |
321 ms |
64020 KB |
Output is correct |
34 |
Correct |
378 ms |
74824 KB |
Output is correct |
35 |
Correct |
365 ms |
65992 KB |
Output is correct |
36 |
Correct |
366 ms |
69900 KB |
Output is correct |
37 |
Correct |
265 ms |
65228 KB |
Output is correct |
38 |
Correct |
264 ms |
65216 KB |
Output is correct |
39 |
Correct |
294 ms |
72204 KB |
Output is correct |
40 |
Correct |
292 ms |
72124 KB |
Output is correct |
41 |
Correct |
259 ms |
63564 KB |
Output is correct |
42 |
Correct |
273 ms |
64344 KB |
Output is correct |
43 |
Correct |
269 ms |
63408 KB |
Output is correct |
44 |
Correct |
283 ms |
67280 KB |
Output is correct |
45 |
Correct |
258 ms |
63308 KB |
Output is correct |
46 |
Correct |
243 ms |
63384 KB |
Output is correct |
47 |
Correct |
280 ms |
67680 KB |
Output is correct |
48 |
Correct |
279 ms |
67616 KB |
Output is correct |
49 |
Correct |
356 ms |
67292 KB |
Output is correct |
50 |
Correct |
356 ms |
67340 KB |
Output is correct |
51 |
Correct |
344 ms |
74060 KB |
Output is correct |
52 |
Correct |
349 ms |
73548 KB |
Output is correct |
53 |
Correct |
347 ms |
65704 KB |
Output is correct |
54 |
Correct |
322 ms |
66108 KB |
Output is correct |
55 |
Correct |
304 ms |
64388 KB |
Output is correct |
56 |
Correct |
335 ms |
69204 KB |
Output is correct |
57 |
Correct |
299 ms |
64996 KB |
Output is correct |
58 |
Correct |
294 ms |
65508 KB |
Output is correct |
59 |
Correct |
278 ms |
67684 KB |
Output is correct |