#include "horses.h"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int N,nn;
int next[500002],before[500002];
long long ans,mulx;
long long x[500002],y[500002];
int two[2000000];
long long seg[2000000];
#define MOD 1000000007
long long inv(long long value){
if(value == 1) return 1;
long long tmp = (inv(MOD%value)*((-MOD)/value));
tmp %= MOD;
if(tmp < 0) tmp += MOD;
return tmp;
}
void update(int node,long long value){
seg[node] = value;
node /= 2;
while(node > 0){
seg[node] = max(seg[node*2],seg[(node*2)+1]);
node /= 2;
}
}
int s,e;
long long big;
void finding(int node,int left,int right){
if(e < left || right < s) return;
if(s <= left && right <= e){
big = max(big,seg[node]);
return;
}
int mid = (left+right)/2;
finding(node*2,left,mid);
finding((node*2)+1,mid+1,right);
}
long long get(){
big = 0;
finding(1,1,nn);
return big;
}
long long print[50];
void process(){
int i,t,cnt;
long long tmp,tt;
ans = 0; tmp = 1; cnt = 0;
t = next[N+1];
while(t != 0){
s = t; e = before[t]-1;
print[++cnt] = get();
tmp *= x[t];
if(tmp >= 1000000000) break;
t = next[t];
}
if(t == 0){
s = 1; e = before[0]-1;
if(s <= e){
ans = get();
}
tmp = 1; t = before[0];
for(i=cnt; i>=1; i--){
tmp *= x[t];
ans = max(ans,tmp*print[i]);
t = before[t];
}
ans %= MOD;
}else{ // warning
tt = mulx * inv(tmp%MOD); tt %= MOD;
tt *= x[t]; tt %= MOD;
tmp = 1;
for(i=cnt; i>=1; i--){
ans = max(ans,tmp*print[i]);
t = before[t];
tmp *= x[t];
}
ans %= MOD;
ans *= tt; ans %= MOD;
}
}
int init(int n, int X[], int Y[]) {
int i,j,t;
mulx = 1;
for(i=1; i<=n; i++){
x[i] = (long long)X[i-1];
mulx *= x[i]; mulx %= MOD;
y[i] = (long long)Y[i-1];
}
N = n;
for(nn=1; nn<N; nn*=2);
for(i=1; i<=N; i++) update(nn+i-1,y[i]);
t = N+1;
for(i=N; i>=1; i--){
if(x[i] > 1){
before[i] = t;
next[t] = i;
t = i;
j = nn+i-1;
while(j > 0){
two[j]++;
j /= 2;
}
}
}
before[0] = t;
process();
return (int)ans;
}
int s2,e2,found;
void find2(int node,int left,int right){
if(found != -1) return;
if(e2 < left || right < s2) return;
if(s2 <= left && right <= e2){
if(two[node] != 0){
found = node;
}
return;
}
int mid = (left+right)/2;
find2(node*2,left,mid);
find2((node*2)+1,mid+1,right);
}
int updateX(int pos, int val) {
int t;
pos++;
mulx *= inv(x[pos]); mulx %= MOD;
mulx *= (long long)val; mulx %= MOD;
if(x[pos] == 1 && val > 1){
if(pos == N){
before[N] = N+1;
next[N] = next[N+1];
next[N+1] = N;
before[next[N]] = N;
}else{
s2 = pos+1; e2 = N; found = -1;
find2(1,1,nn);
if(found == -1) found = N+1;
else{
while(found < nn){
if(two[found*2] != 0) found = (found*2);
else found = (found*2)+1;
}
found -= (nn-1);
}
next[pos] = next[found];
before[pos] = found;
before[next[found]] = pos;
next[found] = pos;
}
t = nn+pos-1;
while(t > 0){
two[t]++;
t /= 2;
}
}else if(x[pos] > 1 && val == 1){
next[before[pos]] = next[pos];
before[next[pos]] = before[pos];
t = nn+pos-1;
while(t > 0){
two[t]--;
t /= 2;
}
}
x[pos] = (long long)val;
process();
if(ans < 0) exit(0);
return (int)ans;
}
int updateY(int pos, int val) {
update(nn+pos,(long long)val);
process();
if(ans < 0) exit(0);
return (int)ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
36244 KB |
Output is correct |
2 |
Correct |
0 ms |
36244 KB |
Output is correct |
3 |
Correct |
0 ms |
36244 KB |
Output is correct |
4 |
Correct |
0 ms |
36244 KB |
Output is correct |
5 |
Correct |
0 ms |
36244 KB |
Output is correct |
6 |
Correct |
0 ms |
36244 KB |
Output is correct |
7 |
Correct |
0 ms |
36244 KB |
Output is correct |
8 |
Correct |
0 ms |
36244 KB |
Output is correct |
9 |
Correct |
0 ms |
36244 KB |
Output is correct |
10 |
Correct |
0 ms |
36244 KB |
Output is correct |
11 |
Correct |
0 ms |
36244 KB |
Output is correct |
12 |
Correct |
0 ms |
36244 KB |
Output is correct |
13 |
Correct |
0 ms |
36244 KB |
Output is correct |
14 |
Correct |
0 ms |
36244 KB |
Output is correct |
15 |
Correct |
0 ms |
36244 KB |
Output is correct |
16 |
Correct |
0 ms |
36244 KB |
Output is correct |
17 |
Correct |
0 ms |
36244 KB |
Output is correct |
18 |
Correct |
0 ms |
36244 KB |
Output is correct |
19 |
Correct |
0 ms |
36244 KB |
Output is correct |
20 |
Correct |
0 ms |
36244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
36244 KB |
Output is correct |
2 |
Correct |
0 ms |
36244 KB |
Output is correct |
3 |
Correct |
0 ms |
36244 KB |
Output is correct |
4 |
Correct |
0 ms |
36244 KB |
Output is correct |
5 |
Correct |
0 ms |
36244 KB |
Output is correct |
6 |
Correct |
0 ms |
36244 KB |
Output is correct |
7 |
Correct |
0 ms |
36244 KB |
Output is correct |
8 |
Correct |
0 ms |
36244 KB |
Output is correct |
9 |
Correct |
0 ms |
36244 KB |
Output is correct |
10 |
Correct |
0 ms |
36244 KB |
Output is correct |
11 |
Correct |
0 ms |
36244 KB |
Output is correct |
12 |
Correct |
0 ms |
36244 KB |
Output is correct |
13 |
Correct |
0 ms |
36244 KB |
Output is correct |
14 |
Correct |
0 ms |
36244 KB |
Output is correct |
15 |
Correct |
0 ms |
36244 KB |
Output is correct |
16 |
Correct |
0 ms |
36244 KB |
Output is correct |
17 |
Correct |
0 ms |
36244 KB |
Output is correct |
18 |
Correct |
0 ms |
36244 KB |
Output is correct |
19 |
Correct |
0 ms |
36244 KB |
Output is correct |
20 |
Correct |
0 ms |
36244 KB |
Output is correct |
21 |
Correct |
0 ms |
36244 KB |
Output is correct |
22 |
Correct |
0 ms |
36244 KB |
Output is correct |
23 |
Correct |
0 ms |
36244 KB |
Output is correct |
24 |
Correct |
0 ms |
36244 KB |
Output is correct |
25 |
Correct |
0 ms |
36244 KB |
Output is correct |
26 |
Correct |
0 ms |
36244 KB |
Output is correct |
27 |
Correct |
4 ms |
36244 KB |
Output is correct |
28 |
Correct |
0 ms |
36244 KB |
Output is correct |
29 |
Correct |
0 ms |
36244 KB |
Output is correct |
30 |
Correct |
0 ms |
36244 KB |
Output is correct |
31 |
Correct |
0 ms |
36244 KB |
Output is correct |
32 |
Correct |
4 ms |
36244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
490 ms |
40156 KB |
Output is correct |
2 |
Correct |
218 ms |
40156 KB |
Output is correct |
3 |
Correct |
206 ms |
40156 KB |
Output is correct |
4 |
Correct |
245 ms |
40156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
36244 KB |
Output is correct |
2 |
Correct |
0 ms |
36244 KB |
Output is correct |
3 |
Correct |
0 ms |
36244 KB |
Output is correct |
4 |
Correct |
0 ms |
36244 KB |
Output is correct |
5 |
Correct |
0 ms |
36244 KB |
Output is correct |
6 |
Correct |
0 ms |
36244 KB |
Output is correct |
7 |
Correct |
2 ms |
36244 KB |
Output is correct |
8 |
Correct |
0 ms |
36244 KB |
Output is correct |
9 |
Correct |
1 ms |
36244 KB |
Output is correct |
10 |
Correct |
0 ms |
36244 KB |
Output is correct |
11 |
Correct |
0 ms |
36244 KB |
Output is correct |
12 |
Correct |
0 ms |
36244 KB |
Output is correct |
13 |
Correct |
0 ms |
36244 KB |
Output is correct |
14 |
Correct |
0 ms |
36244 KB |
Output is correct |
15 |
Correct |
0 ms |
36244 KB |
Output is correct |
16 |
Correct |
0 ms |
36244 KB |
Output is correct |
17 |
Correct |
0 ms |
36244 KB |
Output is correct |
18 |
Correct |
0 ms |
36244 KB |
Output is correct |
19 |
Correct |
0 ms |
36244 KB |
Output is correct |
20 |
Correct |
0 ms |
36244 KB |
Output is correct |
21 |
Correct |
0 ms |
36244 KB |
Output is correct |
22 |
Correct |
0 ms |
36244 KB |
Output is correct |
23 |
Correct |
0 ms |
36244 KB |
Output is correct |
24 |
Correct |
0 ms |
36244 KB |
Output is correct |
25 |
Correct |
3 ms |
36244 KB |
Output is correct |
26 |
Correct |
0 ms |
36244 KB |
Output is correct |
27 |
Correct |
0 ms |
36244 KB |
Output is correct |
28 |
Correct |
0 ms |
36244 KB |
Output is correct |
29 |
Correct |
0 ms |
36244 KB |
Output is correct |
30 |
Correct |
3 ms |
36244 KB |
Output is correct |
31 |
Correct |
0 ms |
36244 KB |
Output is correct |
32 |
Correct |
3 ms |
36244 KB |
Output is correct |
33 |
Correct |
85 ms |
40156 KB |
Output is correct |
34 |
Correct |
73 ms |
40156 KB |
Output is correct |
35 |
Correct |
138 ms |
40156 KB |
Output is correct |
36 |
Correct |
88 ms |
40156 KB |
Output is correct |
37 |
Correct |
105 ms |
40156 KB |
Output is correct |
38 |
Correct |
87 ms |
40156 KB |
Output is correct |
39 |
Correct |
44 ms |
40156 KB |
Output is correct |
40 |
Correct |
125 ms |
40156 KB |
Output is correct |
41 |
Correct |
79 ms |
40156 KB |
Output is correct |
42 |
Correct |
86 ms |
40156 KB |
Output is correct |
43 |
Correct |
118 ms |
40156 KB |
Output is correct |
44 |
Correct |
83 ms |
40156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
36244 KB |
Output is correct |
2 |
Correct |
0 ms |
36244 KB |
Output is correct |
3 |
Correct |
0 ms |
36244 KB |
Output is correct |
4 |
Correct |
0 ms |
36244 KB |
Output is correct |
5 |
Correct |
0 ms |
36244 KB |
Output is correct |
6 |
Correct |
0 ms |
36244 KB |
Output is correct |
7 |
Correct |
0 ms |
36244 KB |
Output is correct |
8 |
Correct |
0 ms |
36244 KB |
Output is correct |
9 |
Correct |
0 ms |
36244 KB |
Output is correct |
10 |
Correct |
0 ms |
36244 KB |
Output is correct |
11 |
Correct |
0 ms |
36244 KB |
Output is correct |
12 |
Correct |
0 ms |
36244 KB |
Output is correct |
13 |
Correct |
0 ms |
36244 KB |
Output is correct |
14 |
Correct |
0 ms |
36244 KB |
Output is correct |
15 |
Correct |
0 ms |
36244 KB |
Output is correct |
16 |
Correct |
0 ms |
36244 KB |
Output is correct |
17 |
Correct |
0 ms |
36244 KB |
Output is correct |
18 |
Correct |
0 ms |
36244 KB |
Output is correct |
19 |
Correct |
0 ms |
36244 KB |
Output is correct |
20 |
Correct |
0 ms |
36244 KB |
Output is correct |
21 |
Correct |
0 ms |
36244 KB |
Output is correct |
22 |
Correct |
0 ms |
36244 KB |
Output is correct |
23 |
Correct |
0 ms |
36244 KB |
Output is correct |
24 |
Correct |
0 ms |
36244 KB |
Output is correct |
25 |
Correct |
0 ms |
36244 KB |
Output is correct |
26 |
Correct |
0 ms |
36244 KB |
Output is correct |
27 |
Correct |
2 ms |
36244 KB |
Output is correct |
28 |
Correct |
3 ms |
36244 KB |
Output is correct |
29 |
Correct |
0 ms |
36244 KB |
Output is correct |
30 |
Correct |
0 ms |
36244 KB |
Output is correct |
31 |
Correct |
0 ms |
36244 KB |
Output is correct |
32 |
Correct |
0 ms |
36244 KB |
Output is correct |
33 |
Correct |
468 ms |
40156 KB |
Output is correct |
34 |
Correct |
168 ms |
40156 KB |
Output is correct |
35 |
Correct |
218 ms |
40156 KB |
Output is correct |
36 |
Correct |
244 ms |
40156 KB |
Output is correct |
37 |
Correct |
77 ms |
40156 KB |
Output is correct |
38 |
Correct |
72 ms |
40156 KB |
Output is correct |
39 |
Correct |
115 ms |
40156 KB |
Output is correct |
40 |
Correct |
96 ms |
40156 KB |
Output is correct |
41 |
Correct |
95 ms |
40156 KB |
Output is correct |
42 |
Correct |
71 ms |
40156 KB |
Output is correct |
43 |
Correct |
53 ms |
40156 KB |
Output is correct |
44 |
Correct |
114 ms |
40156 KB |
Output is correct |
45 |
Correct |
65 ms |
40156 KB |
Output is correct |
46 |
Correct |
84 ms |
40156 KB |
Output is correct |
47 |
Correct |
67 ms |
40156 KB |
Output is correct |
48 |
Correct |
79 ms |
40156 KB |
Output is correct |
49 |
Correct |
221 ms |
40156 KB |
Output is correct |
50 |
Correct |
191 ms |
40156 KB |
Output is correct |
51 |
Correct |
216 ms |
40156 KB |
Output is correct |
52 |
Correct |
147 ms |
40156 KB |
Output is correct |
53 |
Correct |
579 ms |
40156 KB |
Output is correct |
54 |
Correct |
277 ms |
40156 KB |
Output is correct |
55 |
Correct |
118 ms |
40156 KB |
Output is correct |
56 |
Correct |
304 ms |
40156 KB |
Output is correct |
57 |
Correct |
305 ms |
40156 KB |
Output is correct |
58 |
Correct |
417 ms |
40156 KB |
Output is correct |
59 |
Correct |
83 ms |
40156 KB |
Output is correct |