#include "horses.h"
#include "bits/stdc++.h"
using namespace std;
long long multpl[2000000];
long long maxi[2000000];
long long X[500000];
set<int>st;
int n,N,L,R;
long long multp(int l=1,int r=N,int in=1){
if(l>R||r<L)return 1;
if(l>=L&&r<=R)return multpl[in];
int mid=(l+r)/2;
return (multp(l,mid,in*2)*multp(mid+1,r,in*2+1))%1000000007;
}
long long mx(int l=1,int r=N,int in=1){
if(l>R||r<L)return 0;
if(l>=L&&r<=R)return maxi[in];
int mid=(l+r)/2;
return max(mx(l,mid,in*2),mx(mid+1,r,in*2+1));
}
int slv(){
deque<int>v;
int g=31;
auto it=st.end();
while(it!=st.begin()&&g--){
it--;
v.push_back(*it);
}
sort(v.begin(),v.end());
if(v.empty()||v[0]!=0)v.push_front(0);
long long ans=0,in=0;
long double LNGDB=0,f=1,a;
for(int i=0;i<v.size();i++){
f*=X[v[i]];
L=v[i]+1;
R=n;
a=f*mx();
if(a>LNGDB){
LNGDB=a;
in=v[i];
}
}
L=1;
R=in+1;
ans=multp();
L=in+1;
R=n;
ans*=mx();
return ans%1000000007;
}
int init(int nn, int x[], int y[]) {
n=nn;
N=exp2(ceil(log2(n)));
for(auto &i:multpl)i=1;
for(int i=0;i<n;i++){
if(x[i]!=1)st.insert(i);
X[i]=x[i];
}
for(int i=0;i<n;i++)multpl[i+N]=x[i];
for(int i=N-1;i;i--)multpl[i]=(multpl[i*2]*multpl[i*2+1])%1000000007;
for(int i=0;i<n;i++)maxi[i+N]=y[i];
for(int i=N-1;i;i--)maxi[i]=max(maxi[i*2],maxi[i*2+1]);
return slv();
}
int updateX(int pos, int val) {
if(X[pos]!=1)st.erase(pos);
X[pos]=val;
if(val!=1)st.insert(pos);
int in=pos+N;
multpl[in]=val;
in/=2;
while(in){
multpl[in]=(multpl[in*2]*multpl[in*2+1])%1000000007;
in/=2;
}
return slv();
}
int updateY(int pos, int val) {
int in=pos+N;
maxi[in]=val;
in/=2;
while(in){
maxi[in]=max(maxi[in*2],maxi[in*2+1]);
in/=2;
}
return slv();
}
Compilation message
horses.cpp: In function 'int slv()':
horses.cpp:34:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
horses.cpp:45:6: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
45 | R=in+1;
| ~~^~
horses.cpp:47:6: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
47 | L=in+1;
| ~~^~
horses.cpp:50:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
50 | return ans%1000000007;
| ~~~^~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:55:8: warning: conversion from 'double' to 'int' may change value [-Wfloat-conversion]
55 | N=exp2(ceil(log2(n)));
| ~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15924 KB |
Output is correct |
2 |
Correct |
8 ms |
15932 KB |
Output is correct |
3 |
Correct |
8 ms |
15928 KB |
Output is correct |
4 |
Correct |
8 ms |
15928 KB |
Output is correct |
5 |
Correct |
6 ms |
15928 KB |
Output is correct |
6 |
Correct |
7 ms |
15952 KB |
Output is correct |
7 |
Correct |
8 ms |
15924 KB |
Output is correct |
8 |
Correct |
7 ms |
15912 KB |
Output is correct |
9 |
Correct |
7 ms |
15912 KB |
Output is correct |
10 |
Correct |
6 ms |
15956 KB |
Output is correct |
11 |
Correct |
6 ms |
15956 KB |
Output is correct |
12 |
Correct |
7 ms |
15956 KB |
Output is correct |
13 |
Correct |
8 ms |
15956 KB |
Output is correct |
14 |
Correct |
8 ms |
15956 KB |
Output is correct |
15 |
Correct |
7 ms |
15956 KB |
Output is correct |
16 |
Correct |
7 ms |
15956 KB |
Output is correct |
17 |
Correct |
7 ms |
15956 KB |
Output is correct |
18 |
Correct |
7 ms |
15956 KB |
Output is correct |
19 |
Correct |
8 ms |
15936 KB |
Output is correct |
20 |
Correct |
8 ms |
15956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15956 KB |
Output is correct |
2 |
Correct |
7 ms |
15956 KB |
Output is correct |
3 |
Correct |
6 ms |
15956 KB |
Output is correct |
4 |
Correct |
7 ms |
15956 KB |
Output is correct |
5 |
Correct |
7 ms |
15936 KB |
Output is correct |
6 |
Correct |
9 ms |
15956 KB |
Output is correct |
7 |
Correct |
7 ms |
15956 KB |
Output is correct |
8 |
Correct |
10 ms |
15952 KB |
Output is correct |
9 |
Correct |
8 ms |
15956 KB |
Output is correct |
10 |
Correct |
7 ms |
15956 KB |
Output is correct |
11 |
Correct |
9 ms |
15956 KB |
Output is correct |
12 |
Correct |
7 ms |
15976 KB |
Output is correct |
13 |
Correct |
7 ms |
15956 KB |
Output is correct |
14 |
Correct |
7 ms |
15956 KB |
Output is correct |
15 |
Correct |
8 ms |
15920 KB |
Output is correct |
16 |
Correct |
8 ms |
15932 KB |
Output is correct |
17 |
Correct |
7 ms |
15932 KB |
Output is correct |
18 |
Correct |
7 ms |
15956 KB |
Output is correct |
19 |
Correct |
9 ms |
15920 KB |
Output is correct |
20 |
Correct |
7 ms |
15956 KB |
Output is correct |
21 |
Correct |
7 ms |
15956 KB |
Output is correct |
22 |
Correct |
10 ms |
15956 KB |
Output is correct |
23 |
Correct |
13 ms |
15936 KB |
Output is correct |
24 |
Correct |
10 ms |
15956 KB |
Output is correct |
25 |
Correct |
11 ms |
15984 KB |
Output is correct |
26 |
Correct |
11 ms |
16084 KB |
Output is correct |
27 |
Correct |
10 ms |
15956 KB |
Output is correct |
28 |
Correct |
11 ms |
15968 KB |
Output is correct |
29 |
Correct |
8 ms |
16004 KB |
Output is correct |
30 |
Correct |
11 ms |
16068 KB |
Output is correct |
31 |
Correct |
9 ms |
15956 KB |
Output is correct |
32 |
Correct |
12 ms |
16028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
648 ms |
59996 KB |
Output is correct |
2 |
Correct |
739 ms |
68888 KB |
Output is correct |
3 |
Correct |
680 ms |
60032 KB |
Output is correct |
4 |
Correct |
800 ms |
63984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15956 KB |
Output is correct |
2 |
Correct |
7 ms |
15956 KB |
Output is correct |
3 |
Correct |
9 ms |
15956 KB |
Output is correct |
4 |
Correct |
8 ms |
15928 KB |
Output is correct |
5 |
Correct |
9 ms |
15956 KB |
Output is correct |
6 |
Correct |
7 ms |
16084 KB |
Output is correct |
7 |
Correct |
8 ms |
15920 KB |
Output is correct |
8 |
Correct |
7 ms |
15920 KB |
Output is correct |
9 |
Correct |
7 ms |
15956 KB |
Output is correct |
10 |
Correct |
7 ms |
15920 KB |
Output is correct |
11 |
Correct |
7 ms |
15956 KB |
Output is correct |
12 |
Correct |
7 ms |
15904 KB |
Output is correct |
13 |
Correct |
7 ms |
15956 KB |
Output is correct |
14 |
Correct |
7 ms |
15924 KB |
Output is correct |
15 |
Correct |
15 ms |
15956 KB |
Output is correct |
16 |
Correct |
8 ms |
15956 KB |
Output is correct |
17 |
Correct |
8 ms |
15956 KB |
Output is correct |
18 |
Correct |
8 ms |
15932 KB |
Output is correct |
19 |
Correct |
7 ms |
15964 KB |
Output is correct |
20 |
Correct |
7 ms |
15904 KB |
Output is correct |
21 |
Correct |
8 ms |
15956 KB |
Output is correct |
22 |
Correct |
8 ms |
15900 KB |
Output is correct |
23 |
Correct |
11 ms |
15992 KB |
Output is correct |
24 |
Correct |
10 ms |
15956 KB |
Output is correct |
25 |
Correct |
10 ms |
16048 KB |
Output is correct |
26 |
Correct |
11 ms |
16084 KB |
Output is correct |
27 |
Correct |
11 ms |
16084 KB |
Output is correct |
28 |
Correct |
12 ms |
16052 KB |
Output is correct |
29 |
Correct |
8 ms |
15996 KB |
Output is correct |
30 |
Correct |
12 ms |
16080 KB |
Output is correct |
31 |
Correct |
10 ms |
15956 KB |
Output is correct |
32 |
Correct |
10 ms |
16024 KB |
Output is correct |
33 |
Correct |
105 ms |
36084 KB |
Output is correct |
34 |
Correct |
82 ms |
36008 KB |
Output is correct |
35 |
Correct |
235 ms |
66268 KB |
Output is correct |
36 |
Correct |
214 ms |
66296 KB |
Output is correct |
37 |
Correct |
95 ms |
34124 KB |
Output is correct |
38 |
Correct |
157 ms |
46864 KB |
Output is correct |
39 |
Correct |
46 ms |
33788 KB |
Output is correct |
40 |
Correct |
216 ms |
61364 KB |
Output is correct |
41 |
Correct |
56 ms |
33960 KB |
Output is correct |
42 |
Correct |
69 ms |
33940 KB |
Output is correct |
43 |
Correct |
171 ms |
61576 KB |
Output is correct |
44 |
Correct |
182 ms |
61688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15956 KB |
Output is correct |
2 |
Correct |
7 ms |
15928 KB |
Output is correct |
3 |
Correct |
7 ms |
15956 KB |
Output is correct |
4 |
Correct |
7 ms |
15860 KB |
Output is correct |
5 |
Correct |
8 ms |
15872 KB |
Output is correct |
6 |
Correct |
9 ms |
15956 KB |
Output is correct |
7 |
Correct |
7 ms |
15932 KB |
Output is correct |
8 |
Correct |
8 ms |
15924 KB |
Output is correct |
9 |
Correct |
7 ms |
15956 KB |
Output is correct |
10 |
Correct |
8 ms |
15928 KB |
Output is correct |
11 |
Correct |
7 ms |
15924 KB |
Output is correct |
12 |
Correct |
7 ms |
15956 KB |
Output is correct |
13 |
Correct |
6 ms |
15932 KB |
Output is correct |
14 |
Correct |
7 ms |
15928 KB |
Output is correct |
15 |
Correct |
7 ms |
15888 KB |
Output is correct |
16 |
Correct |
7 ms |
15932 KB |
Output is correct |
17 |
Correct |
7 ms |
15956 KB |
Output is correct |
18 |
Correct |
7 ms |
15956 KB |
Output is correct |
19 |
Correct |
8 ms |
15940 KB |
Output is correct |
20 |
Correct |
7 ms |
15924 KB |
Output is correct |
21 |
Correct |
7 ms |
15956 KB |
Output is correct |
22 |
Correct |
9 ms |
15956 KB |
Output is correct |
23 |
Correct |
15 ms |
15940 KB |
Output is correct |
24 |
Correct |
11 ms |
15940 KB |
Output is correct |
25 |
Correct |
11 ms |
16084 KB |
Output is correct |
26 |
Correct |
10 ms |
16068 KB |
Output is correct |
27 |
Correct |
10 ms |
15956 KB |
Output is correct |
28 |
Correct |
11 ms |
15956 KB |
Output is correct |
29 |
Correct |
7 ms |
15936 KB |
Output is correct |
30 |
Correct |
11 ms |
16072 KB |
Output is correct |
31 |
Correct |
10 ms |
15956 KB |
Output is correct |
32 |
Correct |
10 ms |
15956 KB |
Output is correct |
33 |
Correct |
645 ms |
60200 KB |
Output is correct |
34 |
Correct |
743 ms |
68976 KB |
Output is correct |
35 |
Correct |
693 ms |
60076 KB |
Output is correct |
36 |
Correct |
767 ms |
63900 KB |
Output is correct |
37 |
Correct |
109 ms |
35892 KB |
Output is correct |
38 |
Correct |
87 ms |
35916 KB |
Output is correct |
39 |
Correct |
224 ms |
66188 KB |
Output is correct |
40 |
Correct |
231 ms |
66180 KB |
Output is correct |
41 |
Correct |
92 ms |
34064 KB |
Output is correct |
42 |
Correct |
172 ms |
46788 KB |
Output is correct |
43 |
Correct |
37 ms |
33868 KB |
Output is correct |
44 |
Correct |
241 ms |
61232 KB |
Output is correct |
45 |
Correct |
73 ms |
33896 KB |
Output is correct |
46 |
Correct |
72 ms |
34008 KB |
Output is correct |
47 |
Correct |
178 ms |
61680 KB |
Output is correct |
48 |
Correct |
184 ms |
61660 KB |
Output is correct |
49 |
Correct |
700 ms |
38964 KB |
Output is correct |
50 |
Correct |
568 ms |
38896 KB |
Output is correct |
51 |
Correct |
674 ms |
68092 KB |
Output is correct |
52 |
Correct |
667 ms |
67572 KB |
Output is correct |
53 |
Correct |
693 ms |
37328 KB |
Output is correct |
54 |
Correct |
712 ms |
51004 KB |
Output is correct |
55 |
Correct |
144 ms |
34892 KB |
Output is correct |
56 |
Correct |
823 ms |
63124 KB |
Output is correct |
57 |
Correct |
391 ms |
35632 KB |
Output is correct |
58 |
Correct |
483 ms |
36176 KB |
Output is correct |
59 |
Correct |
157 ms |
61756 KB |
Output is correct |