# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
241000 |
2020-06-22T03:11:48 Z |
ant101 |
Horses (IOI15_horses) |
C++14 |
|
846 ms |
45432 KB |
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define left (index << 1)
#define right ((index << 1) + 1)
#define mid ((l + r) / 2)
const int MAXA = (int)1e9 + 1;
const int mod = (int)1e9 + 7;
int n;
vector<int> x, y;
vector<int> p, p2;
void buildP(int index, int l, int r)
{
if (l == r)
{
p[index] = p2[index] = x[l];
return;
}
buildP(left, l, mid);
buildP(right, mid + 1, r);
p[index] = (1LL * p[left] * p[right]) % mod;
p2[index] = min((ll)MAXA, 1LL * p2[left] * p2[right]);
}
void updateP(int index, int l, int r, int ind)
{
if (!(ind >= l && ind <= r))
return;
if (l == r)
{
p[index] = p2[index] = x[ind];
return;
}
updateP(left, l, mid, ind);
updateP(right, mid + 1, r, ind);
p[index] = (1LL * p[left] * p[right]) % mod;
p2[index] = min((ll)MAXA, 1LL * p2[left] * p2[right]);
}
int queryP(int index, int l, int r, int ql, int qr, bool foo)
{
if (l > qr || r < ql)
return 1;
if (l >= ql && r <= qr)
return foo ? p2[index] : p[index];
if (foo)
return min((ll)MAXA, (1LL * queryP(left, l, mid, ql, qr, true) * queryP(right, mid + 1, r, ql, qr, true)));
return (1LL * queryP(left, l, mid, ql, qr, false) * queryP(right, mid + 1, r, ql, qr, false)) % mod;
}
vector<int> st;
void build(int index, int l, int r)
{
if (l == r)
{
st[index] = l;
return;
}
build(left, l, mid);
build(right, mid + 1, r);
int lll = st[left],
rrr = st[right];
if (queryP(1, 0, n - 1, lll + 1, rrr, true) >= ceil(y[lll] / (double)y[rrr]))
st[index] = rrr;
else st[index] = lll;
}
void update(int index, int l, int r, int ind)
{
if (!(ind >= l && ind <= r))
return;
if (l == r)
return;
update(left, l, mid, ind);
update(right, mid + 1, r, ind);
int lll = st[left],
rrr = st[right];
if (queryP(1, 0, n - 1, lll + 1, rrr, true) >= (int)ceil(y[lll] / (double)y[rrr]))
st[index] = rrr;
else st[index] = lll;
}
int solve()
{
int ind = st[1];
//cout << ind << endl;
return (1LL * queryP(1, 0, n - 1, 0, ind, false) * y[ind]) % mod;
}
int init(int N, int X[], int Y[])
{
x = y = vector<int>(N);
for (int i = 0; i < N; i++)
x[i] = X[i], y[i] = Y[i];
p = p2 = st = vector<int>(N * 4);
n = N;
buildP(1, 0, n - 1);
build(1, 0, n - 1);
return solve();
}
int updateX(int pos, int val)
{
x[pos] = val;
updateP(1, 0, n - 1, pos);
update(1, 0, n - 1, pos);
//buildP(1, 0, n - 1);
//build(1, 0, n - 1);
return solve();
}
int updateY(int pos, int val)
{
y[pos] = val;
update(1, 0, n - 1, pos);
//buildP(1, 0, n - 1);
//build(1, 0, n - 1);
return solve();
}
Compilation message
horses.cpp: In function 'void buildP(int, int, int)':
horses.cpp:30:43: warning: conversion to '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' from 'long long int' may alter its value [-Wconversion]
p[index] = (1LL * p[left] * p[right]) % mod;
~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:31:20: warning: conversion to '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' from 'long long int' may alter its value [-Wconversion]
p2[index] = min((ll)MAXA, 1LL * p2[left] * p2[right]);
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'void updateP(int, int, int, int)':
horses.cpp:44:43: warning: conversion to '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' from 'long long int' may alter its value [-Wconversion]
p[index] = (1LL * p[left] * p[right]) % mod;
~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:45:20: warning: conversion to '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' from 'long long int' may alter its value [-Wconversion]
p2[index] = min((ll)MAXA, 1LL * p2[left] * p2[right]);
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int queryP(int, int, int, int, int, bool)':
horses.cpp:54:19: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return min((ll)MAXA, (1LL * queryP(left, l, mid, ql, qr, true) * queryP(right, mid + 1, r, ql, qr, true)));
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:55:99: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return (1LL * queryP(left, l, mid, ql, qr, false) * queryP(right, mid + 1, r, ql, qr, false)) % mod;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int solve()':
horses.cpp:93:64: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return (1LL * queryP(1, 0, n - 1, 0, ind, false) * y[ind]) % mod;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
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 |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
256 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 |
128 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
4 ms |
256 KB |
Output is correct |
19 |
Correct |
4 ms |
256 KB |
Output is correct |
20 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
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 |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
256 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 |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
256 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 |
256 KB |
Output is correct |
18 |
Correct |
4 ms |
256 KB |
Output is correct |
19 |
Correct |
4 ms |
256 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
21 |
Correct |
5 ms |
256 KB |
Output is correct |
22 |
Correct |
4 ms |
288 KB |
Output is correct |
23 |
Correct |
7 ms |
384 KB |
Output is correct |
24 |
Correct |
6 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
6 ms |
384 KB |
Output is correct |
27 |
Correct |
6 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
384 KB |
Output is correct |
29 |
Correct |
6 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
384 KB |
Output is correct |
32 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
447 ms |
36472 KB |
Output is correct |
2 |
Correct |
509 ms |
45432 KB |
Output is correct |
3 |
Correct |
584 ms |
36472 KB |
Output is correct |
4 |
Correct |
588 ms |
40312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
256 KB |
Output is correct |
19 |
Correct |
5 ms |
256 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
256 KB |
Output is correct |
23 |
Correct |
6 ms |
384 KB |
Output is correct |
24 |
Correct |
7 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
384 KB |
Output is correct |
29 |
Correct |
6 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
512 KB |
Output is correct |
32 |
Correct |
6 ms |
384 KB |
Output is correct |
33 |
Correct |
226 ms |
35628 KB |
Output is correct |
34 |
Correct |
213 ms |
35704 KB |
Output is correct |
35 |
Correct |
201 ms |
42616 KB |
Output is correct |
36 |
Correct |
192 ms |
42612 KB |
Output is correct |
37 |
Correct |
183 ms |
33916 KB |
Output is correct |
38 |
Correct |
174 ms |
34808 KB |
Output is correct |
39 |
Correct |
149 ms |
33784 KB |
Output is correct |
40 |
Correct |
177 ms |
37624 KB |
Output is correct |
41 |
Correct |
160 ms |
33784 KB |
Output is correct |
42 |
Correct |
162 ms |
33792 KB |
Output is correct |
43 |
Correct |
145 ms |
38136 KB |
Output is correct |
44 |
Correct |
153 ms |
38008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
256 KB |
Output is correct |
19 |
Correct |
4 ms |
256 KB |
Output is correct |
20 |
Correct |
5 ms |
256 KB |
Output is correct |
21 |
Correct |
5 ms |
256 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
6 ms |
384 KB |
Output is correct |
24 |
Correct |
6 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
6 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
6 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
384 KB |
Output is correct |
32 |
Correct |
6 ms |
384 KB |
Output is correct |
33 |
Correct |
446 ms |
36472 KB |
Output is correct |
34 |
Correct |
493 ms |
45304 KB |
Output is correct |
35 |
Correct |
587 ms |
36728 KB |
Output is correct |
36 |
Correct |
606 ms |
40312 KB |
Output is correct |
37 |
Correct |
230 ms |
35704 KB |
Output is correct |
38 |
Correct |
214 ms |
35704 KB |
Output is correct |
39 |
Correct |
205 ms |
42564 KB |
Output is correct |
40 |
Correct |
189 ms |
42616 KB |
Output is correct |
41 |
Correct |
177 ms |
33976 KB |
Output is correct |
42 |
Correct |
172 ms |
34808 KB |
Output is correct |
43 |
Correct |
143 ms |
33792 KB |
Output is correct |
44 |
Correct |
162 ms |
37624 KB |
Output is correct |
45 |
Correct |
166 ms |
33912 KB |
Output is correct |
46 |
Correct |
155 ms |
33784 KB |
Output is correct |
47 |
Correct |
139 ms |
37984 KB |
Output is correct |
48 |
Correct |
149 ms |
38008 KB |
Output is correct |
49 |
Correct |
846 ms |
38080 KB |
Output is correct |
50 |
Correct |
778 ms |
37752 KB |
Output is correct |
51 |
Correct |
541 ms |
44536 KB |
Output is correct |
52 |
Correct |
381 ms |
44024 KB |
Output is correct |
53 |
Correct |
644 ms |
36092 KB |
Output is correct |
54 |
Correct |
501 ms |
36704 KB |
Output is correct |
55 |
Correct |
351 ms |
34912 KB |
Output is correct |
56 |
Correct |
371 ms |
39492 KB |
Output is correct |
57 |
Correct |
480 ms |
35452 KB |
Output is correct |
58 |
Correct |
429 ms |
35960 KB |
Output is correct |
59 |
Correct |
145 ms |
38012 KB |
Output is correct |