/**
* user: ppavic
* fname: Patrik
* lname: Pavić
* task: horses
* score: 100.0
* date: 2019-06-23 09:59:51.864112
*/
#include "horses.h"
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
#define PB push_back
using namespace std;
typedef __int128 ll;
typedef pair < int, int > pii;
typedef vector < int > vi;
const int OFF = (1 << 19);
const ll MOD = 1e9 + 7;
const int N = 1e6 + 500;
ll mul[2 * OFF];
ll mx[2 * OFF], n, X[N], Y[N];
set < int > s;
vi v;
ll query_mul(int i,int a,int b,int lo,int hi){
if(lo <= a && b <= hi) return mul[i];
if(a > hi || b < lo) return 1;
return query_mul(2 * i, a, (a + b) / 2, lo, hi) * query_mul(2 * i + 1, (a + b) / 2 + 1, b, lo, hi) % MOD;
}
ll query_mx(int i,int a,int b,int lo,int hi){
if(lo <= a && b <= hi) return mx[i];
if(a > hi || b < lo) return 1;
return max(query_mx(2 * i, a, (a + b) / 2, lo, hi), query_mx(2 * i + 1, (a + b) / 2 + 1, b, lo, hi));
}
void update_mul(int i,ll X){
if(mul[OFF + i] > 1) s.erase(i);
if(X > 1) s.insert(i);
mul[OFF + i] = X;
for(i = (i + OFF) / 2; i ; i /= 2)
mul[i] = mul[2 * i] * mul[2 * i + 1] % MOD;
}
void update_mx(int i, ll Y){
mx[OFF + i] = Y;
for(i = (i + OFF) / 2; i ; i /= 2)
mx[i] = max(mx[2 * i], mx[2 * i + 1]);
}
ll solve(){
ll cur = 1, sol = 1;
vi v;
auto it = s.rbegin();
v.PB(n);
//printf("s %d\n", s.size());
for(; v.size() <= s.size() && cur < MOD;){
v.PB(*it); cur *= X[*it]; it++;
if(cur >= (ll)MOD) break;
}
reverse(v.begin(), v.end());
cur = 1;
for(int i = 0;i + 1 < v.size();i++){
cur *= (ll)X[v[i]];
//printf("cur %lld mx %lld\n", cur, query_mx(1, 0, OFF - 1,v[i], v[i + 1] - 1));
sol = max(sol, cur * query_mx(1, 0, OFF - 1,v[i], v[i + 1] - 1));
}
//printf("gotov\n");
if(v.size() > s.size()) return max(sol, (ll)mx[1]) % MOD;
return sol % (ll)MOD * query_mul(1, 0, OFF - 1, 0, v[0] - 1) % MOD;
}
int init(int N, int XX[], int YY[]) {
for(int i = 0;i < N;i++) X[i] = XX[i], Y[i] = YY[i];
n = N;
for(int i = 0;i < n;i++)
update_mul(i, X[i]), update_mx(i, Y[i]);
return solve();
}
int updateX(int pos, int val) {
update_mul(pos, val); X[pos] = val;
return solve();
}
int updateY(int pos, int val) {
update_mx(pos, val); Y[pos] = val;
return solve();
}
Compilation message
horses.cpp: In function 'void update_mul(int, ll)':
horses.cpp:46:27: warning: declaration of 'X' shadows a global declaration [-Wshadow]
void update_mul(int i,ll X){
^
horses.cpp:30:20: note: shadowed declaration is here
ll mx[2 * OFF], n, X[N], Y[N];
^
horses.cpp: In function 'void update_mx(int, ll)':
horses.cpp:54:27: warning: declaration of 'Y' shadows a global declaration [-Wshadow]
void update_mx(int i, ll Y){
^
horses.cpp:30:26: note: shadowed declaration is here
ll mx[2 * OFF], n, X[N], Y[N];
^
horses.cpp: In function 'll solve()':
horses.cpp:62:5: warning: declaration of 'v' shadows a global declaration [-Wshadow]
vi v;
^
horses.cpp:32:4: note: shadowed declaration is here
vi v;
^
horses.cpp:64:8: warning: conversion to 'std::vector<int>::value_type {aka int}' from 'll {aka __int128}' may alter its value [-Wconversion]
v.PB(n);
^
horses.cpp:72:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i + 1 < v.size();i++){
~~~~~~^~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:83:35: warning: declaration of 'N' shadows a global declaration [-Wshadow]
int init(int N, int XX[], int YY[]) {
^
horses.cpp:27:11: note: shadowed declaration is here
const int N = 1e6 + 500;
^
horses.cpp:88:14: warning: conversion to 'int' from 'll {aka __int128}' may alter its value [-Wconversion]
return solve();
~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:93:14: warning: conversion to 'int' from 'll {aka __int128}' may alter its value [-Wconversion]
return solve();
~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:98:14: warning: conversion to 'int' from 'll {aka __int128}' may alter its value [-Wconversion]
return solve();
~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
512 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
4 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
4 ms |
512 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
4 ms |
512 KB |
Output is correct |
16 |
Correct |
4 ms |
512 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
19 |
Correct |
5 ms |
380 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
4 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
512 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
4 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
4 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
512 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
640 KB |
Output is correct |
24 |
Correct |
6 ms |
640 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
6 ms |
640 KB |
Output is correct |
27 |
Correct |
12 ms |
640 KB |
Output is correct |
28 |
Correct |
8 ms |
640 KB |
Output is correct |
29 |
Correct |
6 ms |
512 KB |
Output is correct |
30 |
Correct |
7 ms |
640 KB |
Output is correct |
31 |
Correct |
9 ms |
640 KB |
Output is correct |
32 |
Correct |
11 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
979 ms |
79644 KB |
Output is correct |
2 |
Correct |
538 ms |
88292 KB |
Output is correct |
3 |
Correct |
564 ms |
79692 KB |
Output is correct |
4 |
Correct |
656 ms |
83396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
4 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
4 ms |
512 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
512 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
4 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
512 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
4 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
4 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
640 KB |
Output is correct |
24 |
Correct |
6 ms |
640 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
6 ms |
640 KB |
Output is correct |
27 |
Correct |
12 ms |
640 KB |
Output is correct |
28 |
Correct |
8 ms |
640 KB |
Output is correct |
29 |
Correct |
6 ms |
640 KB |
Output is correct |
30 |
Correct |
6 ms |
640 KB |
Output is correct |
31 |
Correct |
9 ms |
640 KB |
Output is correct |
32 |
Correct |
11 ms |
640 KB |
Output is correct |
33 |
Correct |
191 ms |
55416 KB |
Output is correct |
34 |
Correct |
188 ms |
55548 KB |
Output is correct |
35 |
Correct |
352 ms |
85752 KB |
Output is correct |
36 |
Correct |
354 ms |
85752 KB |
Output is correct |
37 |
Correct |
269 ms |
53624 KB |
Output is correct |
38 |
Correct |
251 ms |
66296 KB |
Output is correct |
39 |
Correct |
192 ms |
53368 KB |
Output is correct |
40 |
Correct |
325 ms |
80760 KB |
Output is correct |
41 |
Correct |
218 ms |
53412 KB |
Output is correct |
42 |
Correct |
240 ms |
53496 KB |
Output is correct |
43 |
Correct |
318 ms |
81120 KB |
Output is correct |
44 |
Correct |
317 ms |
81384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
4 ms |
512 KB |
Output is correct |
9 |
Correct |
4 ms |
512 KB |
Output is correct |
10 |
Correct |
6 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
512 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 |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
512 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
8 ms |
640 KB |
Output is correct |
24 |
Correct |
6 ms |
640 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
6 ms |
640 KB |
Output is correct |
27 |
Correct |
12 ms |
640 KB |
Output is correct |
28 |
Correct |
8 ms |
640 KB |
Output is correct |
29 |
Correct |
6 ms |
512 KB |
Output is correct |
30 |
Correct |
6 ms |
640 KB |
Output is correct |
31 |
Correct |
9 ms |
640 KB |
Output is correct |
32 |
Correct |
11 ms |
640 KB |
Output is correct |
33 |
Correct |
1020 ms |
79736 KB |
Output is correct |
34 |
Correct |
541 ms |
88312 KB |
Output is correct |
35 |
Correct |
557 ms |
79540 KB |
Output is correct |
36 |
Correct |
671 ms |
83576 KB |
Output is correct |
37 |
Correct |
185 ms |
55416 KB |
Output is correct |
38 |
Correct |
185 ms |
55416 KB |
Output is correct |
39 |
Correct |
349 ms |
85752 KB |
Output is correct |
40 |
Correct |
348 ms |
85696 KB |
Output is correct |
41 |
Correct |
275 ms |
53596 KB |
Output is correct |
42 |
Correct |
253 ms |
66300 KB |
Output is correct |
43 |
Correct |
186 ms |
53368 KB |
Output is correct |
44 |
Correct |
329 ms |
80760 KB |
Output is correct |
45 |
Correct |
231 ms |
53496 KB |
Output is correct |
46 |
Correct |
251 ms |
53540 KB |
Output is correct |
47 |
Correct |
310 ms |
81148 KB |
Output is correct |
48 |
Correct |
309 ms |
81144 KB |
Output is correct |
49 |
Correct |
358 ms |
58528 KB |
Output is correct |
50 |
Correct |
318 ms |
58488 KB |
Output is correct |
51 |
Correct |
545 ms |
87544 KB |
Output is correct |
52 |
Correct |
454 ms |
87124 KB |
Output is correct |
53 |
Correct |
1018 ms |
56952 KB |
Output is correct |
54 |
Correct |
534 ms |
70524 KB |
Output is correct |
55 |
Correct |
283 ms |
54392 KB |
Output is correct |
56 |
Correct |
461 ms |
82696 KB |
Output is correct |
57 |
Correct |
586 ms |
55032 KB |
Output is correct |
58 |
Correct |
838 ms |
55612 KB |
Output is correct |
59 |
Correct |
316 ms |
81400 KB |
Output is correct |