#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> pi;
struct rmq{
pi tree[1050000];
int lim;
void init(int n, int *a){
for(lim = 1; lim <= n; lim <<= 1);
for(int i=0; i<n; i++){
tree[i + lim] = pi(a[i], i);
}
for(int i=lim-1; i; i--){
tree[i] = max(tree[2*i], tree[2*i+1]);
}
}
void upd(int x, int v){
x += lim;
tree[x] = pi(v, x - lim);
while(x > 1){
x >>= 1;
tree[x] = max(tree[2*x], tree[2*x+1]);
}
}
pi q(int s, int e){
s += lim;
e += lim;
pi ret(0,0);
while(s < e){
if(s%2 == 1) ret = max(ret,tree[s++]);
if(e%2 == 0) ret = max(ret,tree[e--]);
s >>= 1;
e >>= 1;
}
if(s == e) ret = max(ret,tree[s]);
return ret;
}
}rmq;
struct gob{
lint tree[1050000], lim;
void init(int n, int *a){
for(lim = 1; lim <= n; lim <<= 1);
fill(tree, tree + 2 * lim + 1, 1);
for(int i=0; i<n; i++){
tree[i + lim] = a[i];
}
for(int i=lim-1; i; i--){
tree[i] = tree[2*i] * tree[2*i+1] % mod;
}
}
void upd(int x, int v){
x += lim;
tree[x] = v;
while(x > 1){
x >>= 1;
tree[x] = tree[2*x] * tree[2*x+1] % mod;
}
}
int q(int s, int e){
s += lim;
e += lim;
lint ret = 1;
while(s < e){
if(s%2 == 1) ret *= tree[s++], ret %= mod;
if(e%2 == 0) ret *= tree[e--], ret %= mod;
s >>= 1;
e >>= 1;
}
if(s == e) ret *= tree[s], ret %= mod;
return ret;
}
}gob;
int n, x[500005], y[500005];
set<int> s;
int solve(){
auto ite = --s.end();
auto its = --s.end();
its--;
lint ret = -1;
int retp = n;
for(int i=0; i<32 && ite != s.begin(); i++){
pi t = rmq.q(*its, *ite - 1);
if(ret < t.first){
retp = t.second;
ret = t.first;
}
ret *= x[*its];
if(ret > 2e9 || its == s.begin()) break;
its--;
ite--;
}
return 1ll * gob.q(0, retp) * y[retp] % mod;
}
int init(int N, int X[], int Y[]) {
n = N;
gob.init(N, X);
rmq.init(N, Y);
for(int i=0; i<N; i++){
x[i] = X[i], y[i] = Y[i];
if(X[i] != 1) s.insert(i);
}
s.insert(0);
s.insert(N);
return solve();
}
int updateX(int pos, int val) {
if(x[pos] != 1){
s.erase(pos);
s.insert(0);
}
x[pos] = val;
gob.upd(pos, val);
if(x[pos] != 1){
s.insert(pos);
}
return solve();
}
int updateY(int pos, int val) {
rmq.upd(pos, val);
y[pos] = val;
return solve();
}
Compilation message
horses.cpp: In member function 'void gob::init(int, int*)':
horses.cpp:51:22: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
51 | for(int i=lim-1; i; i--){
| ~~~^~
horses.cpp: In member function 'void gob::upd(int, int)':
horses.cpp:56:11: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
56 | x += lim;
| ~~^~~~~~
horses.cpp: In member function 'int gob::q(int, int)':
horses.cpp:64:11: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
64 | s += lim;
| ~~^~~~~~
horses.cpp:65:11: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
65 | e += lim;
| ~~^~~~~~
horses.cpp:74:16: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
74 | return ret;
| ^~~
horses.cpp: In function 'int solve()':
horses.cpp:95:12: warning: conversion from 'lint' {aka 'long long int'} to 'double' may change value [-Wconversion]
95 | if(ret > 2e9 || its == s.begin()) break;
| ^~~
horses.cpp:99:43: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
99 | return 1ll * gob.q(0, retp) * y[retp] % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8532 KB |
Output is correct |
2 |
Correct |
4 ms |
8532 KB |
Output is correct |
3 |
Correct |
4 ms |
8528 KB |
Output is correct |
4 |
Correct |
4 ms |
8532 KB |
Output is correct |
5 |
Correct |
3 ms |
8484 KB |
Output is correct |
6 |
Correct |
3 ms |
8532 KB |
Output is correct |
7 |
Correct |
3 ms |
8532 KB |
Output is correct |
8 |
Correct |
3 ms |
8532 KB |
Output is correct |
9 |
Correct |
3 ms |
8548 KB |
Output is correct |
10 |
Correct |
3 ms |
8532 KB |
Output is correct |
11 |
Correct |
3 ms |
8528 KB |
Output is correct |
12 |
Correct |
3 ms |
8532 KB |
Output is correct |
13 |
Correct |
3 ms |
8528 KB |
Output is correct |
14 |
Correct |
3 ms |
8532 KB |
Output is correct |
15 |
Correct |
4 ms |
8532 KB |
Output is correct |
16 |
Correct |
3 ms |
8532 KB |
Output is correct |
17 |
Correct |
3 ms |
8532 KB |
Output is correct |
18 |
Correct |
3 ms |
8532 KB |
Output is correct |
19 |
Correct |
3 ms |
8528 KB |
Output is correct |
20 |
Correct |
3 ms |
8532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8532 KB |
Output is correct |
2 |
Correct |
3 ms |
8520 KB |
Output is correct |
3 |
Correct |
3 ms |
8436 KB |
Output is correct |
4 |
Correct |
3 ms |
8532 KB |
Output is correct |
5 |
Correct |
3 ms |
8532 KB |
Output is correct |
6 |
Correct |
3 ms |
8532 KB |
Output is correct |
7 |
Correct |
3 ms |
8532 KB |
Output is correct |
8 |
Correct |
3 ms |
8532 KB |
Output is correct |
9 |
Correct |
3 ms |
8532 KB |
Output is correct |
10 |
Correct |
3 ms |
8460 KB |
Output is correct |
11 |
Correct |
3 ms |
8532 KB |
Output is correct |
12 |
Correct |
3 ms |
8528 KB |
Output is correct |
13 |
Correct |
3 ms |
8528 KB |
Output is correct |
14 |
Correct |
3 ms |
8528 KB |
Output is correct |
15 |
Correct |
3 ms |
8532 KB |
Output is correct |
16 |
Correct |
3 ms |
8532 KB |
Output is correct |
17 |
Correct |
3 ms |
8532 KB |
Output is correct |
18 |
Correct |
3 ms |
8528 KB |
Output is correct |
19 |
Correct |
3 ms |
8476 KB |
Output is correct |
20 |
Correct |
3 ms |
8532 KB |
Output is correct |
21 |
Correct |
3 ms |
8532 KB |
Output is correct |
22 |
Correct |
4 ms |
8532 KB |
Output is correct |
23 |
Correct |
4 ms |
8540 KB |
Output is correct |
24 |
Correct |
3 ms |
8604 KB |
Output is correct |
25 |
Correct |
4 ms |
8660 KB |
Output is correct |
26 |
Correct |
3 ms |
8544 KB |
Output is correct |
27 |
Correct |
4 ms |
8532 KB |
Output is correct |
28 |
Correct |
3 ms |
8540 KB |
Output is correct |
29 |
Correct |
3 ms |
8576 KB |
Output is correct |
30 |
Correct |
4 ms |
8532 KB |
Output is correct |
31 |
Correct |
3 ms |
8532 KB |
Output is correct |
32 |
Correct |
4 ms |
8532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
152 ms |
52780 KB |
Output is correct |
2 |
Correct |
235 ms |
61600 KB |
Output is correct |
3 |
Correct |
208 ms |
52752 KB |
Output is correct |
4 |
Correct |
256 ms |
56652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8532 KB |
Output is correct |
2 |
Correct |
3 ms |
8528 KB |
Output is correct |
3 |
Correct |
3 ms |
8532 KB |
Output is correct |
4 |
Correct |
3 ms |
8532 KB |
Output is correct |
5 |
Correct |
3 ms |
8532 KB |
Output is correct |
6 |
Correct |
3 ms |
8532 KB |
Output is correct |
7 |
Correct |
3 ms |
8532 KB |
Output is correct |
8 |
Correct |
3 ms |
8532 KB |
Output is correct |
9 |
Correct |
3 ms |
8532 KB |
Output is correct |
10 |
Correct |
3 ms |
8532 KB |
Output is correct |
11 |
Correct |
3 ms |
8532 KB |
Output is correct |
12 |
Correct |
4 ms |
8532 KB |
Output is correct |
13 |
Correct |
6 ms |
8496 KB |
Output is correct |
14 |
Correct |
3 ms |
8532 KB |
Output is correct |
15 |
Correct |
3 ms |
8532 KB |
Output is correct |
16 |
Correct |
3 ms |
8532 KB |
Output is correct |
17 |
Correct |
3 ms |
8528 KB |
Output is correct |
18 |
Correct |
3 ms |
8528 KB |
Output is correct |
19 |
Correct |
3 ms |
8532 KB |
Output is correct |
20 |
Correct |
3 ms |
8528 KB |
Output is correct |
21 |
Correct |
3 ms |
8532 KB |
Output is correct |
22 |
Correct |
3 ms |
8524 KB |
Output is correct |
23 |
Correct |
3 ms |
8532 KB |
Output is correct |
24 |
Correct |
4 ms |
8532 KB |
Output is correct |
25 |
Correct |
4 ms |
8660 KB |
Output is correct |
26 |
Correct |
4 ms |
8540 KB |
Output is correct |
27 |
Correct |
4 ms |
8532 KB |
Output is correct |
28 |
Correct |
3 ms |
8532 KB |
Output is correct |
29 |
Correct |
3 ms |
8532 KB |
Output is correct |
30 |
Correct |
4 ms |
8540 KB |
Output is correct |
31 |
Correct |
3 ms |
8532 KB |
Output is correct |
32 |
Correct |
4 ms |
8532 KB |
Output is correct |
33 |
Correct |
34 ms |
28644 KB |
Output is correct |
34 |
Correct |
34 ms |
28700 KB |
Output is correct |
35 |
Correct |
139 ms |
58964 KB |
Output is correct |
36 |
Correct |
137 ms |
58848 KB |
Output is correct |
37 |
Correct |
33 ms |
26844 KB |
Output is correct |
38 |
Correct |
69 ms |
39548 KB |
Output is correct |
39 |
Correct |
25 ms |
26576 KB |
Output is correct |
40 |
Correct |
123 ms |
54060 KB |
Output is correct |
41 |
Correct |
23 ms |
26700 KB |
Output is correct |
42 |
Correct |
24 ms |
26668 KB |
Output is correct |
43 |
Correct |
120 ms |
54356 KB |
Output is correct |
44 |
Correct |
120 ms |
54380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8536 KB |
Output is correct |
2 |
Correct |
3 ms |
8532 KB |
Output is correct |
3 |
Correct |
3 ms |
8532 KB |
Output is correct |
4 |
Correct |
3 ms |
8532 KB |
Output is correct |
5 |
Correct |
3 ms |
8532 KB |
Output is correct |
6 |
Correct |
3 ms |
8532 KB |
Output is correct |
7 |
Correct |
3 ms |
8532 KB |
Output is correct |
8 |
Correct |
3 ms |
8532 KB |
Output is correct |
9 |
Correct |
3 ms |
8532 KB |
Output is correct |
10 |
Correct |
4 ms |
8532 KB |
Output is correct |
11 |
Correct |
3 ms |
8532 KB |
Output is correct |
12 |
Correct |
3 ms |
8532 KB |
Output is correct |
13 |
Correct |
3 ms |
8532 KB |
Output is correct |
14 |
Correct |
3 ms |
8532 KB |
Output is correct |
15 |
Correct |
3 ms |
8532 KB |
Output is correct |
16 |
Correct |
3 ms |
8532 KB |
Output is correct |
17 |
Correct |
3 ms |
8532 KB |
Output is correct |
18 |
Correct |
3 ms |
8532 KB |
Output is correct |
19 |
Correct |
3 ms |
8532 KB |
Output is correct |
20 |
Correct |
3 ms |
8532 KB |
Output is correct |
21 |
Correct |
3 ms |
8532 KB |
Output is correct |
22 |
Correct |
3 ms |
8532 KB |
Output is correct |
23 |
Correct |
3 ms |
8540 KB |
Output is correct |
24 |
Correct |
3 ms |
8532 KB |
Output is correct |
25 |
Correct |
5 ms |
8660 KB |
Output is correct |
26 |
Correct |
3 ms |
8660 KB |
Output is correct |
27 |
Correct |
4 ms |
8532 KB |
Output is correct |
28 |
Correct |
3 ms |
8532 KB |
Output is correct |
29 |
Correct |
3 ms |
8468 KB |
Output is correct |
30 |
Correct |
4 ms |
8660 KB |
Output is correct |
31 |
Correct |
3 ms |
8540 KB |
Output is correct |
32 |
Correct |
4 ms |
8532 KB |
Output is correct |
33 |
Correct |
152 ms |
52812 KB |
Output is correct |
34 |
Correct |
239 ms |
61716 KB |
Output is correct |
35 |
Correct |
206 ms |
52768 KB |
Output is correct |
36 |
Correct |
253 ms |
56644 KB |
Output is correct |
37 |
Correct |
34 ms |
28696 KB |
Output is correct |
38 |
Correct |
33 ms |
28632 KB |
Output is correct |
39 |
Correct |
143 ms |
58896 KB |
Output is correct |
40 |
Correct |
144 ms |
58892 KB |
Output is correct |
41 |
Correct |
33 ms |
26752 KB |
Output is correct |
42 |
Correct |
79 ms |
39548 KB |
Output is correct |
43 |
Correct |
23 ms |
26568 KB |
Output is correct |
44 |
Correct |
128 ms |
54036 KB |
Output is correct |
45 |
Correct |
23 ms |
26684 KB |
Output is correct |
46 |
Correct |
26 ms |
26700 KB |
Output is correct |
47 |
Correct |
122 ms |
54424 KB |
Output is correct |
48 |
Correct |
122 ms |
54440 KB |
Output is correct |
49 |
Correct |
79 ms |
31692 KB |
Output is correct |
50 |
Correct |
75 ms |
31692 KB |
Output is correct |
51 |
Correct |
187 ms |
60780 KB |
Output is correct |
52 |
Correct |
168 ms |
60364 KB |
Output is correct |
53 |
Correct |
130 ms |
29992 KB |
Output is correct |
54 |
Correct |
108 ms |
43476 KB |
Output is correct |
55 |
Correct |
62 ms |
27680 KB |
Output is correct |
56 |
Correct |
176 ms |
55772 KB |
Output is correct |
57 |
Correct |
59 ms |
28356 KB |
Output is correct |
58 |
Correct |
78 ms |
28732 KB |
Output is correct |
59 |
Correct |
122 ms |
54516 KB |
Output is correct |