# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
851985 |
2023-09-21T03:27:00 Z |
ntkphong |
Horses (IOI15_horses) |
C++14 |
|
590 ms |
54772 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int lim = 1e9;
const int mod = 1e9 + 7;
const int mxN = 5e5 + 10;
int n;
int aX[mxN], aY[mxN];
pair<int, int> ST[mxN << 2];
map<int, int> mp;
void update(int node, int l, int r, int x) {
if(r < x || x < l) return ;
if(l == r) {
ST[node].first = aX[l];
ST[node].second = aY[l];
return ;
}
int mid = (l + r) / 2;
update(node * 2, l, mid, x);
update(node * 2 + 1, mid + 1, r, x);
ST[node].first = 1LL * ST[node * 2].first * ST[node * 2 + 1].first % mod;
ST[node].second = max(ST[node * 2].second, ST[node * 2 + 1].second);
}
int get_mul(int node, int l, int r, int x) {
if(l == r)
return ST[node].first;
int mid = (l + r) / 2;
if(x <= mid) {
return get_mul(node * 2, l, mid, x);
} else {
return 1LL * ST[node * 2].first * get_mul(node * 2 + 1, mid + 1, r, x) % mod;
}
}
int get_max(int node, int l, int r, int u, int v) {
if(r < u || v < l) return 0;
if(u <= l && r <= v)
return ST[node].second;
int mid = (l + r) / 2;
return max(get_max(node * 2, l, mid, u, v), get_max(node * 2 + 1, mid + 1, r, u, v));
}
int find_max() {
long double frmax = aY[n - 1];
int mul = 1;
int res = 1LL * get_mul(1, 0, n - 1, n - 1) * aY[n - 1] % mod;
for(auto i = mp.rbegin(); i != mp.rend(); ) {
int r = i->first;
r -- ;
if(1LL * mul * aX[i->first] > 1LL * lim) break ;
mul *= aX[i->first];
i ++ ;
if(i != mp.rend()) {
int l = i->first;
if(l > r) continue ;
int x = get_max(1, 0, n - 1, l, r);
long double frnew = (long double) x / mul;
if(frnew > frmax) {
frmax = frnew;
res = 1LL * get_mul(1, 0, n - 1, l) * x % mod;
}
}
}
return res;
}
int init(int N, int X[], int Y[]) {
n = N;
for(int i = 0; i < N; i ++) aX[i] = X[i];
for(int i = 0; i < N; i ++) aY[i] = Y[i];
mp.insert({0, 1});
mp.insert({N - 1, 1});
for(int i = 0; i < N; i ++) {
if(aX[i] > 1) {
mp.insert({i, 1});
}
}
for(int i = 0; i < N; i ++) update(1, 0, N - 1, i);
return find_max();
}
int updateX(int pos, int val) {
aX[pos] = val;
update(1, 0, n - 1, pos);
if(pos != n - 1 && pos != 0 && aX[pos] <= 1) {
if(mp.find(pos) != mp.end()) {
mp.erase(pos);
}
}
if(aX[pos] > 1) mp.insert({pos, 1});
return find_max();
}
int updateY(int pos, int val) {
aY[pos] = val;
update(1, 0, n - 1, pos);
return find_max();
}
Compilation message
horses.cpp: In function 'void update(int, int, int, int)':
horses.cpp:27:72: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
27 | ST[node].first = 1LL * ST[node * 2].first * ST[node * 2 + 1].first % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int get_mul(int, int, int, int)':
horses.cpp:39:80: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
39 | return 1LL * ST[node * 2].first * get_mul(node * 2 + 1, mid + 1, r, x) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int find_max()':
horses.cpp:56:61: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
56 | int res = 1LL * get_mul(1, 0, n - 1, n - 1) * aY[n - 1] % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:75:57: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
75 | res = 1LL * get_mul(1, 0, n - 1, l) * x % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4628 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
2 ms |
4440 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
3 ms |
4444 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4440 KB |
Output is correct |
30 |
Correct |
2 ms |
4444 KB |
Output is correct |
31 |
Correct |
2 ms |
4440 KB |
Output is correct |
32 |
Correct |
3 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
557 ms |
42232 KB |
Output is correct |
2 |
Correct |
358 ms |
54720 KB |
Output is correct |
3 |
Correct |
352 ms |
46000 KB |
Output is correct |
4 |
Correct |
418 ms |
49760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4440 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4488 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4440 KB |
Output is correct |
22 |
Correct |
1 ms |
4696 KB |
Output is correct |
23 |
Correct |
2 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
2 ms |
4576 KB |
Output is correct |
26 |
Correct |
1 ms |
4552 KB |
Output is correct |
27 |
Correct |
3 ms |
4444 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4440 KB |
Output is correct |
30 |
Correct |
2 ms |
4444 KB |
Output is correct |
31 |
Correct |
3 ms |
4444 KB |
Output is correct |
32 |
Correct |
3 ms |
4444 KB |
Output is correct |
33 |
Correct |
138 ms |
21808 KB |
Output is correct |
34 |
Correct |
136 ms |
21692 KB |
Output is correct |
35 |
Correct |
274 ms |
52088 KB |
Output is correct |
36 |
Correct |
246 ms |
51924 KB |
Output is correct |
37 |
Correct |
184 ms |
20032 KB |
Output is correct |
38 |
Correct |
185 ms |
33044 KB |
Output is correct |
39 |
Correct |
130 ms |
19788 KB |
Output is correct |
40 |
Correct |
232 ms |
47228 KB |
Output is correct |
41 |
Correct |
145 ms |
19796 KB |
Output is correct |
42 |
Correct |
159 ms |
19864 KB |
Output is correct |
43 |
Correct |
221 ms |
47508 KB |
Output is correct |
44 |
Correct |
226 ms |
47388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
2 ms |
4444 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4588 KB |
Output is correct |
27 |
Correct |
3 ms |
4552 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
2 ms |
4444 KB |
Output is correct |
31 |
Correct |
2 ms |
4552 KB |
Output is correct |
32 |
Correct |
3 ms |
4444 KB |
Output is correct |
33 |
Correct |
570 ms |
46176 KB |
Output is correct |
34 |
Correct |
356 ms |
54772 KB |
Output is correct |
35 |
Correct |
361 ms |
45924 KB |
Output is correct |
36 |
Correct |
396 ms |
49780 KB |
Output is correct |
37 |
Correct |
141 ms |
21668 KB |
Output is correct |
38 |
Correct |
139 ms |
21688 KB |
Output is correct |
39 |
Correct |
253 ms |
52052 KB |
Output is correct |
40 |
Correct |
247 ms |
52128 KB |
Output is correct |
41 |
Correct |
183 ms |
19864 KB |
Output is correct |
42 |
Correct |
182 ms |
32872 KB |
Output is correct |
43 |
Correct |
129 ms |
19792 KB |
Output is correct |
44 |
Correct |
228 ms |
47188 KB |
Output is correct |
45 |
Correct |
150 ms |
20040 KB |
Output is correct |
46 |
Correct |
165 ms |
19856 KB |
Output is correct |
47 |
Correct |
223 ms |
47444 KB |
Output is correct |
48 |
Correct |
228 ms |
47800 KB |
Output is correct |
49 |
Correct |
252 ms |
24756 KB |
Output is correct |
50 |
Correct |
214 ms |
24864 KB |
Output is correct |
51 |
Correct |
370 ms |
54108 KB |
Output is correct |
52 |
Correct |
294 ms |
53584 KB |
Output is correct |
53 |
Correct |
590 ms |
23204 KB |
Output is correct |
54 |
Correct |
346 ms |
36572 KB |
Output is correct |
55 |
Correct |
225 ms |
20820 KB |
Output is correct |
56 |
Correct |
318 ms |
49252 KB |
Output is correct |
57 |
Correct |
380 ms |
21328 KB |
Output is correct |
58 |
Correct |
512 ms |
21892 KB |
Output is correct |
59 |
Correct |
222 ms |
47540 KB |
Output is correct |