# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
380219 |
2021-03-20T14:38:05 Z |
idk321 |
Horses (IOI15_horses) |
C++11 |
|
1485 ms |
52972 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int N = 500000;
const int R = 710;
int n;
int* x;
int* y;
ll tree[4 * N];
int tree2[4 * N];
set<int> tree3;
void spMod(ll& num)
{
if (num >= mod)
{
num %= mod;
num += mod;
}
}
void ins(int i, int a, int b, int node)
{
if (a == b)
{
tree[node] = x[a];
return;
}
int mid = (a + b) / 2;
if (i <= mid) ins(i, a, mid, node * 2);
if (i > mid) ins(i, mid + 1, b, node * 2 + 1);
tree[node] = tree[node * 2] * tree[node *2 + 1];
spMod(tree[node]);
}
void insMax(int i, int a, int b, int node)
{
if (a == b)
{
tree2[node] = y[a];
return;
}
int mid = (a + b) / 2;
if (i <= mid) insMax(i, a, mid, node * 2);
else insMax(i, mid +1, b, node * 2 + 1);
tree2[node] = max(tree2[node * 2], tree2[node * 2 + 1]);
}
ll getFac(int from, int to, int a, int b, int node)
{
if (from <= a && b <= to)
{
return tree[node];
}
int mid = (a + b) / 2;
ll res = 1;
if (from <= mid) res *= getFac(from, to, a, mid, node * 2);
if (to > mid) res *= getFac(from, to, mid +1, b, node * 2 + 1);
spMod(res);
return res;
}
int getMax(int from, int to, int a, int b, int node)
{
if (from <= a && b <= to)
{
return tree2[node];
}
int mid = (a + b) / 2;
int res = 0;
if (from <= mid) res = max(res, getMax(from, to, a, mid, node * 2));
if (to > mid) res = max(res, getMax(from, to, mid +1, b, node * 2 + 1));
return res;
}
ll getBest()
{
int ci = -1;
ll cy = -1;
vector<int> v;
auto it = tree3.rbegin();
while (it != tree3.rend() && v.size() < 31)
{
v.push_back(*it);
it++;
}
while (v.size() < 31) v.push_back(-1);
for (int i = 29; i >= 0; i--)
{
int cur = v[i];
int prev = v[i + 1];
if (cur == -1) continue;
ll ones = 0;
ll yVal = y[cur];
if (cur - prev > 1)
{
ones = getMax(prev + 1, cur - 1, 0, n - 1, 1);
}
if (ones > x[cur] * yVal)
{
cur--;
yVal = ones;
}
if (ci == -1)
{
ci = cur;
cy = yVal;
} else
{
ll fac = getFac(ci + 1, cur, 0, n - 1, 1);
fac *= yVal;
if (fac > cy)
{
cy = yVal;
ci = cur;
}
}
prev = cur;
}
int prev = v[0];
if (prev < n - 1)
{
ll yVal = getMax(prev + 1, n - 1, 0, n - 1, 1);
int cur = n - 1;
if (ci == -1)
{
cy = yVal;
ci = cur;
} else
{
ll fac = getFac(ci + 1, cur, 0, n - 1, 1);
fac *= yVal;
if (fac > cy)
{
cy = yVal;
ci = cur;
}
}
}
ll res = getFac(0, ci, 0, n - 1, 1);
res %= mod;
res *= cy;
res %= mod;
return res;
}
int init(int N, int X[], int Y[]) {
n = N;
x = X;
y = Y;
for (int i = 0; i < n; i++)
{
ins(i, 0, n - 1, 1);
insMax(i, 0, n - 1, 1);
if (x[i] != 1) tree3.insert(i);
}
//cout << best[0] << endl;
return getBest() % mod;
}
int updateX(int pos, int val) {
x[pos] = val;
tree3.erase(pos);
if (x[pos] != 1) tree3.insert(pos);
ins(pos, 0, n - 1, 1);
return getBest() % mod;
}
int updateY(int pos, int val) {
y[pos] = val;
insMax(pos, 0, n - 1, 1);
return getBest() % mod;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:182:33: warning: declaration of 'N' shadows a global declaration [-Wshadow]
182 | int init(int N, int X[], int Y[]) {
| ^
horses.cpp:9:11: note: shadowed declaration is here
9 | const int N = 500000;
| ^
horses.cpp:195:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
195 | return getBest() % mod;
| ~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:206:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
206 | return getBest() % mod;
| ~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:214:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
214 | return getBest() % mod;
| ~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
7 ms |
364 KB |
Output is correct |
24 |
Correct |
4 ms |
364 KB |
Output is correct |
25 |
Correct |
5 ms |
364 KB |
Output is correct |
26 |
Correct |
4 ms |
364 KB |
Output is correct |
27 |
Correct |
6 ms |
364 KB |
Output is correct |
28 |
Correct |
5 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
4 ms |
364 KB |
Output is correct |
31 |
Correct |
5 ms |
364 KB |
Output is correct |
32 |
Correct |
7 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
827 ms |
41196 KB |
Output is correct |
2 |
Correct |
943 ms |
41324 KB |
Output is correct |
3 |
Correct |
913 ms |
41068 KB |
Output is correct |
4 |
Correct |
999 ms |
41308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
9 ms |
364 KB |
Output is correct |
24 |
Correct |
4 ms |
364 KB |
Output is correct |
25 |
Correct |
5 ms |
364 KB |
Output is correct |
26 |
Correct |
4 ms |
364 KB |
Output is correct |
27 |
Correct |
6 ms |
364 KB |
Output is correct |
28 |
Correct |
6 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
4 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
364 KB |
Output is correct |
32 |
Correct |
7 ms |
364 KB |
Output is correct |
33 |
Correct |
363 ms |
16876 KB |
Output is correct |
34 |
Correct |
240 ms |
16876 KB |
Output is correct |
35 |
Correct |
392 ms |
40300 KB |
Output is correct |
36 |
Correct |
384 ms |
40300 KB |
Output is correct |
37 |
Correct |
340 ms |
16876 KB |
Output is correct |
38 |
Correct |
325 ms |
28652 KB |
Output is correct |
39 |
Correct |
208 ms |
16620 KB |
Output is correct |
40 |
Correct |
380 ms |
40212 KB |
Output is correct |
41 |
Correct |
217 ms |
16620 KB |
Output is correct |
42 |
Correct |
276 ms |
16748 KB |
Output is correct |
43 |
Correct |
325 ms |
40300 KB |
Output is correct |
44 |
Correct |
332 ms |
40004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
7 ms |
364 KB |
Output is correct |
24 |
Correct |
4 ms |
364 KB |
Output is correct |
25 |
Correct |
4 ms |
364 KB |
Output is correct |
26 |
Correct |
4 ms |
364 KB |
Output is correct |
27 |
Correct |
6 ms |
364 KB |
Output is correct |
28 |
Correct |
5 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
5 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
364 KB |
Output is correct |
32 |
Correct |
7 ms |
364 KB |
Output is correct |
33 |
Correct |
823 ms |
41068 KB |
Output is correct |
34 |
Correct |
935 ms |
41196 KB |
Output is correct |
35 |
Correct |
912 ms |
41068 KB |
Output is correct |
36 |
Correct |
992 ms |
41336 KB |
Output is correct |
37 |
Correct |
382 ms |
16876 KB |
Output is correct |
38 |
Correct |
238 ms |
16748 KB |
Output is correct |
39 |
Correct |
389 ms |
40300 KB |
Output is correct |
40 |
Correct |
389 ms |
40172 KB |
Output is correct |
41 |
Correct |
343 ms |
16828 KB |
Output is correct |
42 |
Correct |
322 ms |
28652 KB |
Output is correct |
43 |
Correct |
202 ms |
16652 KB |
Output is correct |
44 |
Correct |
377 ms |
40140 KB |
Output is correct |
45 |
Correct |
231 ms |
16644 KB |
Output is correct |
46 |
Correct |
279 ms |
16748 KB |
Output is correct |
47 |
Correct |
324 ms |
40044 KB |
Output is correct |
48 |
Correct |
322 ms |
40172 KB |
Output is correct |
49 |
Correct |
1485 ms |
18988 KB |
Output is correct |
50 |
Correct |
752 ms |
24044 KB |
Output is correct |
51 |
Correct |
925 ms |
52972 KB |
Output is correct |
52 |
Correct |
829 ms |
52636 KB |
Output is correct |
53 |
Correct |
1462 ms |
22224 KB |
Output is correct |
54 |
Correct |
1029 ms |
35820 KB |
Output is correct |
55 |
Correct |
408 ms |
19692 KB |
Output is correct |
56 |
Correct |
957 ms |
48108 KB |
Output is correct |
57 |
Correct |
558 ms |
20460 KB |
Output is correct |
58 |
Correct |
1179 ms |
20972 KB |
Output is correct |
59 |
Correct |
328 ms |
46572 KB |
Output is correct |