# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
238067 |
2020-06-09T21:27:26 Z |
Kubin |
Horses (IOI15_horses) |
C++11 |
|
363 ms |
48376 KB |
#include <bits/stdc++.h>
using namespace std;
size_t n;
uint X[1 << 19], Y[1 << 19];
uint64_t product = 1;
set<size_t> idx;
const uint MOD = 1e9 + 7;
uint power(uint a, uint b)
{
uint r = 1;
while(b)
{
if(b % 2) r = (uint64_t) r * a % MOD;
a = (uint64_t) a * a % MOD;
b /= 2;
}
return r;
}
uint inverse(uint x) { return power(x, MOD - 2); }
struct segment_tree
{
const size_t w = 1 << 19;
uint values[1 << 20];
void set(size_t pos, uint val)
{
values[pos += w] = val;
while(pos /= 2)
values[pos] = max(values[2*pos], values[2*pos+1]);
}
uint get(size_t l, size_t r)
{
uint result = 0;
for(l += w, r += w; l < r; l /= 2, r /= 2)
{
if(l % 2) result = max(result, values[l++]);
if(r % 2) result = max(result, values[--r]);
}
return result;
}
} treeY;
uint maxY(size_t l, size_t r)
{
return treeY.get(l, r);
}
uint compute()
{
uint64_t yj = Y[n-1], li = 1, lj = 1;
for(auto it = --idx.end(); *it > 0 and li < UINT_MAX; )
{
auto i = *it, i1 = *prev(it);
auto yi = maxY(i1, i);
if(yj * li < yi * lj)
yj = yi, lj = li;
li *= X[i1];
it = prev(it);
}
return product * inverse(lj) % MOD * yj % MOD;
}
int init(int _n, int x[], int y[])
{
n = _n;
copy(x, x + n, X);
copy(y, y + n, Y);
for(size_t i = 0; i < n; i++)
{
product = product * X[i] % MOD;
if(X[i] > 1) idx.insert(i);
treeY.set(i, Y[i]);
}
idx.insert(0); idx.insert(n);
X[n] = 1;
return compute();
}
int updateX(int pos, int val)
{
product = product * inverse(X[pos]) % MOD * val % MOD;
if(pos and X[pos] > 1) idx.erase(pos);
if(val > 1) idx.insert(pos);
X[pos] = val;
return compute();
}
int updateY(int pos, int val)
{
Y[pos] = val;
treeY.set(pos, val);
return compute();
}
Compilation message
horses.cpp: In function 'uint power(uint, uint)':
horses.cpp:16:40: warning: conversion to 'uint {aka unsigned int}' from 'uint64_t {aka long unsigned int}' may alter its value [-Wconversion]
if(b % 2) r = (uint64_t) r * a % MOD;
~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:17:30: warning: conversion to 'uint {aka unsigned int}' from 'uint64_t {aka long unsigned int}' may alter its value [-Wconversion]
a = (uint64_t) a * a % MOD;
~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'uint compute()':
horses.cpp:65:32: warning: conversion to 'uint {aka unsigned int}' from 'uint64_t {aka long unsigned int}' may alter its value [-Wconversion]
return product * inverse(lj) % MOD * yj % MOD;
^
horses.cpp:65:45: warning: conversion to 'uint {aka unsigned int}' from 'uint64_t {aka long unsigned int}' may alter its value [-Wconversion]
return product * inverse(lj) % MOD * yj % MOD;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
36600 KB |
Output is correct |
2 |
Correct |
313 ms |
36600 KB |
Output is correct |
3 |
Correct |
330 ms |
36612 KB |
Output is correct |
4 |
Correct |
360 ms |
36600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
512 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
512 KB |
Output is correct |
33 |
Correct |
53 ms |
12280 KB |
Output is correct |
34 |
Correct |
54 ms |
12408 KB |
Output is correct |
35 |
Correct |
195 ms |
35704 KB |
Output is correct |
36 |
Correct |
198 ms |
35704 KB |
Output is correct |
37 |
Correct |
54 ms |
12280 KB |
Output is correct |
38 |
Correct |
104 ms |
24184 KB |
Output is correct |
39 |
Correct |
46 ms |
12152 KB |
Output is correct |
40 |
Correct |
182 ms |
41720 KB |
Output is correct |
41 |
Correct |
46 ms |
14328 KB |
Output is correct |
42 |
Correct |
48 ms |
14292 KB |
Output is correct |
43 |
Correct |
173 ms |
41976 KB |
Output is correct |
44 |
Correct |
182 ms |
41952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
216 ms |
36600 KB |
Output is correct |
34 |
Correct |
320 ms |
36728 KB |
Output is correct |
35 |
Correct |
285 ms |
36728 KB |
Output is correct |
36 |
Correct |
363 ms |
36732 KB |
Output is correct |
37 |
Correct |
53 ms |
12280 KB |
Output is correct |
38 |
Correct |
55 ms |
12280 KB |
Output is correct |
39 |
Correct |
205 ms |
35668 KB |
Output is correct |
40 |
Correct |
194 ms |
35704 KB |
Output is correct |
41 |
Correct |
55 ms |
12280 KB |
Output is correct |
42 |
Correct |
106 ms |
24312 KB |
Output is correct |
43 |
Correct |
44 ms |
12160 KB |
Output is correct |
44 |
Correct |
182 ms |
41720 KB |
Output is correct |
45 |
Correct |
45 ms |
14328 KB |
Output is correct |
46 |
Correct |
48 ms |
14328 KB |
Output is correct |
47 |
Correct |
177 ms |
42176 KB |
Output is correct |
48 |
Correct |
178 ms |
41980 KB |
Output is correct |
49 |
Correct |
113 ms |
19320 KB |
Output is correct |
50 |
Correct |
112 ms |
19320 KB |
Output is correct |
51 |
Correct |
267 ms |
48376 KB |
Output is correct |
52 |
Correct |
250 ms |
47996 KB |
Output is correct |
53 |
Correct |
147 ms |
17528 KB |
Output is correct |
54 |
Correct |
169 ms |
31108 KB |
Output is correct |
55 |
Correct |
105 ms |
15224 KB |
Output is correct |
56 |
Correct |
244 ms |
43384 KB |
Output is correct |
57 |
Correct |
94 ms |
15992 KB |
Output is correct |
58 |
Correct |
118 ms |
16368 KB |
Output is correct |
59 |
Correct |
179 ms |
42160 KB |
Output is correct |