# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
206566 |
2020-03-04T03:56:59 Z |
spdskatr |
Horses (IOI15_horses) |
C++14 |
|
289 ms |
41320 KB |
#include "horses.h"
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#define MOD 1000000007
#define SZ (1<<19)
using namespace std;
typedef long long ll;
ll mulst[1<<20], ansst[1<<20];
int x[1<<19], y[1<<19];
// Segtree stores best year to sell horses in range
int st[1<<20];
ll mulover(ll a, ll b) {
if (a == -1 || b == -1) return -1;
if (a * b > 1000000000) return -1;
return a*b;
}
ll prod(int l, int r) {
ll res = 1;
for (l += SZ, r += SZ; res != -1 && l < r; l >>= 1, r >>= 1) {
if (l&1) res = mulover(res, mulst[l++]);
if (r&1) res = mulover(res, mulst[--r]);
}
return res;
}
ll prodans(int l, int r) {
ll res = 1;
for (l += SZ, r += SZ; l < r; l >>= 1, r >>= 1) {
if (l&1) res = (res * ansst[l++]) % MOD;
if (r&1) res = (res * ansst[--r]) % MOD;
}
return res;
}
int stc(int i, int j) {
if (j > 1000000000) return i;
//printf("stc(%d, %d)\n", i, j);
assert(i <= j);
ll val = mulover(prod(i+1, j+1), y[j]);
if (val == -1 || val > y[i]) {
return j;
}
return i;
}
int init(int N, int X[], int Y[]) {
for (int i = 0; i < N; i++) {
x[i] = X[i];
y[i] = Y[i];
mulst[i+SZ] = ansst[i+SZ] = x[i];
st[i+SZ] = i;
}
for (int i = N; i < SZ; i++) {
st[i+SZ] = 2069696969;
}
for (int i = SZ-1; i > 0; i--) {
mulst[i] = mulover(mulst[i<<1], mulst[i<<1|1]);
ansst[i] = (ansst[i<<1] * ansst[i<<1|1]) % MOD;
}
for (int i = SZ-1; i > 0; i--) {
st[i] = stc(st[i<<1], st[i<<1|1]);
}
//printf("Optimal position: %d\n", st[1]);
return (int)((prodans(0, st[1]+1) * y[st[1]]) % MOD);
}
int updateX(int pos, int val) {
x[pos] = val;
int i = pos + SZ;
mulst[i] = val;
ansst[i] = val;
for (int j = i; j > 1; j >>= 1) {
mulst[j>>1] = mulover(mulst[j], mulst[j^1]);
ansst[j>>1] = (ansst[j] * ansst[j^1]) % MOD;
}
i >>= 1;
for (; i > 0; i >>= 1) {
st[i] = stc(st[i<<1], st[i<<1|1]);
}
//printf("Optimal position: %d\n", st[1]);
return (int)((prodans(0, st[1]+1) * y[st[1]]) % MOD);
}
int updateY(int pos, int val) {
y[pos] = val;
int i = pos + SZ;
i >>= 1;
for (; i > 0; i >>= 1) st[i] = stc(st[i<<1], st[i<<1|1]);
//printf("Optimal position: %d\n", st[1]);
return (int)((prodans(0, st[1]+1) * y[st[1]]) % MOD);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
12664 KB |
Output is correct |
2 |
Correct |
14 ms |
12664 KB |
Output is correct |
3 |
Correct |
15 ms |
12664 KB |
Output is correct |
4 |
Correct |
16 ms |
12664 KB |
Output is correct |
5 |
Correct |
15 ms |
12664 KB |
Output is correct |
6 |
Correct |
14 ms |
12664 KB |
Output is correct |
7 |
Correct |
15 ms |
12664 KB |
Output is correct |
8 |
Correct |
16 ms |
12668 KB |
Output is correct |
9 |
Correct |
15 ms |
12664 KB |
Output is correct |
10 |
Correct |
14 ms |
12664 KB |
Output is correct |
11 |
Correct |
15 ms |
12664 KB |
Output is correct |
12 |
Correct |
23 ms |
12664 KB |
Output is correct |
13 |
Correct |
17 ms |
12536 KB |
Output is correct |
14 |
Correct |
15 ms |
12664 KB |
Output is correct |
15 |
Correct |
14 ms |
12664 KB |
Output is correct |
16 |
Correct |
15 ms |
12664 KB |
Output is correct |
17 |
Correct |
15 ms |
12664 KB |
Output is correct |
18 |
Correct |
15 ms |
12664 KB |
Output is correct |
19 |
Correct |
15 ms |
12664 KB |
Output is correct |
20 |
Correct |
15 ms |
12664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
12664 KB |
Output is correct |
2 |
Correct |
15 ms |
12664 KB |
Output is correct |
3 |
Correct |
16 ms |
12664 KB |
Output is correct |
4 |
Correct |
16 ms |
12664 KB |
Output is correct |
5 |
Correct |
15 ms |
12664 KB |
Output is correct |
6 |
Correct |
15 ms |
12664 KB |
Output is correct |
7 |
Correct |
16 ms |
12664 KB |
Output is correct |
8 |
Correct |
15 ms |
12664 KB |
Output is correct |
9 |
Correct |
15 ms |
12664 KB |
Output is correct |
10 |
Correct |
15 ms |
12664 KB |
Output is correct |
11 |
Correct |
15 ms |
12664 KB |
Output is correct |
12 |
Correct |
14 ms |
12664 KB |
Output is correct |
13 |
Correct |
15 ms |
12664 KB |
Output is correct |
14 |
Correct |
15 ms |
12664 KB |
Output is correct |
15 |
Correct |
14 ms |
12664 KB |
Output is correct |
16 |
Correct |
15 ms |
12664 KB |
Output is correct |
17 |
Correct |
15 ms |
12664 KB |
Output is correct |
18 |
Correct |
16 ms |
12664 KB |
Output is correct |
19 |
Correct |
14 ms |
12664 KB |
Output is correct |
20 |
Correct |
15 ms |
12696 KB |
Output is correct |
21 |
Correct |
14 ms |
12664 KB |
Output is correct |
22 |
Correct |
15 ms |
12664 KB |
Output is correct |
23 |
Correct |
17 ms |
12792 KB |
Output is correct |
24 |
Correct |
16 ms |
12664 KB |
Output is correct |
25 |
Correct |
15 ms |
12792 KB |
Output is correct |
26 |
Correct |
15 ms |
12664 KB |
Output is correct |
27 |
Correct |
15 ms |
12664 KB |
Output is correct |
28 |
Correct |
16 ms |
12668 KB |
Output is correct |
29 |
Correct |
16 ms |
12664 KB |
Output is correct |
30 |
Correct |
16 ms |
12664 KB |
Output is correct |
31 |
Correct |
15 ms |
12664 KB |
Output is correct |
32 |
Correct |
15 ms |
12664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
29304 KB |
Output is correct |
2 |
Correct |
220 ms |
29432 KB |
Output is correct |
3 |
Correct |
242 ms |
33144 KB |
Output is correct |
4 |
Correct |
243 ms |
36984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
12664 KB |
Output is correct |
2 |
Correct |
14 ms |
12664 KB |
Output is correct |
3 |
Correct |
17 ms |
12664 KB |
Output is correct |
4 |
Correct |
17 ms |
12652 KB |
Output is correct |
5 |
Correct |
15 ms |
12664 KB |
Output is correct |
6 |
Correct |
16 ms |
12664 KB |
Output is correct |
7 |
Correct |
15 ms |
12664 KB |
Output is correct |
8 |
Correct |
16 ms |
12792 KB |
Output is correct |
9 |
Correct |
14 ms |
12664 KB |
Output is correct |
10 |
Correct |
15 ms |
12664 KB |
Output is correct |
11 |
Correct |
15 ms |
12664 KB |
Output is correct |
12 |
Correct |
14 ms |
12664 KB |
Output is correct |
13 |
Correct |
14 ms |
12668 KB |
Output is correct |
14 |
Correct |
14 ms |
12664 KB |
Output is correct |
15 |
Correct |
15 ms |
12664 KB |
Output is correct |
16 |
Correct |
15 ms |
12664 KB |
Output is correct |
17 |
Correct |
15 ms |
12664 KB |
Output is correct |
18 |
Correct |
15 ms |
12664 KB |
Output is correct |
19 |
Correct |
15 ms |
12664 KB |
Output is correct |
20 |
Correct |
15 ms |
12664 KB |
Output is correct |
21 |
Correct |
14 ms |
12664 KB |
Output is correct |
22 |
Correct |
15 ms |
12792 KB |
Output is correct |
23 |
Correct |
15 ms |
12792 KB |
Output is correct |
24 |
Correct |
15 ms |
12664 KB |
Output is correct |
25 |
Correct |
15 ms |
12664 KB |
Output is correct |
26 |
Correct |
16 ms |
12664 KB |
Output is correct |
27 |
Correct |
15 ms |
12664 KB |
Output is correct |
28 |
Correct |
17 ms |
12668 KB |
Output is correct |
29 |
Correct |
15 ms |
12664 KB |
Output is correct |
30 |
Correct |
15 ms |
12664 KB |
Output is correct |
31 |
Correct |
15 ms |
12664 KB |
Output is correct |
32 |
Correct |
16 ms |
12664 KB |
Output is correct |
33 |
Correct |
74 ms |
32376 KB |
Output is correct |
34 |
Correct |
74 ms |
32376 KB |
Output is correct |
35 |
Correct |
84 ms |
38904 KB |
Output is correct |
36 |
Correct |
88 ms |
38904 KB |
Output is correct |
37 |
Correct |
64 ms |
30584 KB |
Output is correct |
38 |
Correct |
51 ms |
31352 KB |
Output is correct |
39 |
Correct |
54 ms |
30328 KB |
Output is correct |
40 |
Correct |
62 ms |
34300 KB |
Output is correct |
41 |
Correct |
44 ms |
30456 KB |
Output is correct |
42 |
Correct |
49 ms |
30500 KB |
Output is correct |
43 |
Correct |
56 ms |
34680 KB |
Output is correct |
44 |
Correct |
57 ms |
34680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
12792 KB |
Output is correct |
2 |
Correct |
15 ms |
12664 KB |
Output is correct |
3 |
Correct |
15 ms |
12664 KB |
Output is correct |
4 |
Correct |
15 ms |
12664 KB |
Output is correct |
5 |
Correct |
15 ms |
12664 KB |
Output is correct |
6 |
Correct |
15 ms |
12664 KB |
Output is correct |
7 |
Correct |
15 ms |
12664 KB |
Output is correct |
8 |
Correct |
15 ms |
12664 KB |
Output is correct |
9 |
Correct |
16 ms |
12664 KB |
Output is correct |
10 |
Correct |
15 ms |
12664 KB |
Output is correct |
11 |
Correct |
17 ms |
12664 KB |
Output is correct |
12 |
Correct |
15 ms |
12664 KB |
Output is correct |
13 |
Correct |
18 ms |
12664 KB |
Output is correct |
14 |
Correct |
15 ms |
12664 KB |
Output is correct |
15 |
Correct |
17 ms |
12664 KB |
Output is correct |
16 |
Correct |
15 ms |
12664 KB |
Output is correct |
17 |
Correct |
15 ms |
12664 KB |
Output is correct |
18 |
Correct |
16 ms |
12664 KB |
Output is correct |
19 |
Correct |
15 ms |
12664 KB |
Output is correct |
20 |
Correct |
16 ms |
12664 KB |
Output is correct |
21 |
Correct |
21 ms |
12664 KB |
Output is correct |
22 |
Correct |
16 ms |
12664 KB |
Output is correct |
23 |
Correct |
16 ms |
12664 KB |
Output is correct |
24 |
Correct |
15 ms |
12668 KB |
Output is correct |
25 |
Correct |
16 ms |
12668 KB |
Output is correct |
26 |
Correct |
15 ms |
12664 KB |
Output is correct |
27 |
Correct |
16 ms |
12664 KB |
Output is correct |
28 |
Correct |
16 ms |
12792 KB |
Output is correct |
29 |
Correct |
16 ms |
12664 KB |
Output is correct |
30 |
Correct |
16 ms |
12664 KB |
Output is correct |
31 |
Correct |
17 ms |
12664 KB |
Output is correct |
32 |
Correct |
16 ms |
12664 KB |
Output is correct |
33 |
Correct |
82 ms |
33144 KB |
Output is correct |
34 |
Correct |
211 ms |
39544 KB |
Output is correct |
35 |
Correct |
201 ms |
33144 KB |
Output is correct |
36 |
Correct |
220 ms |
36984 KB |
Output is correct |
37 |
Correct |
75 ms |
32376 KB |
Output is correct |
38 |
Correct |
76 ms |
32376 KB |
Output is correct |
39 |
Correct |
83 ms |
38904 KB |
Output is correct |
40 |
Correct |
87 ms |
38904 KB |
Output is correct |
41 |
Correct |
58 ms |
30460 KB |
Output is correct |
42 |
Correct |
49 ms |
31352 KB |
Output is correct |
43 |
Correct |
48 ms |
30328 KB |
Output is correct |
44 |
Correct |
69 ms |
34552 KB |
Output is correct |
45 |
Correct |
44 ms |
30460 KB |
Output is correct |
46 |
Correct |
46 ms |
30456 KB |
Output is correct |
47 |
Correct |
55 ms |
34676 KB |
Output is correct |
48 |
Correct |
54 ms |
34680 KB |
Output is correct |
49 |
Correct |
267 ms |
34296 KB |
Output is correct |
50 |
Correct |
274 ms |
34424 KB |
Output is correct |
51 |
Correct |
133 ms |
41320 KB |
Output is correct |
52 |
Correct |
153 ms |
40776 KB |
Output is correct |
53 |
Correct |
289 ms |
32632 KB |
Output is correct |
54 |
Correct |
134 ms |
33272 KB |
Output is correct |
55 |
Correct |
168 ms |
31480 KB |
Output is correct |
56 |
Correct |
152 ms |
36216 KB |
Output is correct |
57 |
Correct |
125 ms |
32124 KB |
Output is correct |
58 |
Correct |
112 ms |
32632 KB |
Output is correct |
59 |
Correct |
56 ms |
34680 KB |
Output is correct |