#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
long long mod=1e9+7;
int n;
int a[500005];
set<int> st;
long long ost[2000005];
int tree[2000005];
void update(int v, int le, int ri, int idx, int val)
{
if(le==ri) {tree[v]=val; return;}
int mid=(le+ri)/2;
if(idx<=mid) update(2*v, le, mid, idx, val);
else update(2*v+1, mid+1, ri, idx, val);
tree[v]=max(tree[2*v], tree[2*v+1]);
}
int query(int v, int le, int ri, int be, int en)
{
if(en<be) return 0;
if(le>en || ri<be) return 0;
if(be<=le && ri<=en) return tree[v];
int mid=(le+ri)/2;
return max(query(2*v, le, mid, be, en), query(2*v+1, mid+1, ri, be, en));
}
void update2(int v, int le, int ri, int idx, int val)
{
if(le==ri) {ost[v]=val; return;}
int mid=(le+ri)/2;
if(idx<=mid) update2(2*v, le, mid, idx, val);
else update2(2*v+1, mid+1, ri, idx, val);
ost[v]=(ost[2*v]*ost[2*v+1])%mod;
}
long long query2(int v, int le, int ri, int be, int en)
{
if(en<be) return 1;
if(le>en || ri<be) return 1;
if(be<=le && ri<=en) return ost[v];
int mid=(le+ri)/2;
return (query2(2*v, le, mid, be, en)*query2(2*v+1, mid+1, ri, be, en))%mod;
}
int spc[50], cf[50], brt=0;
long long solve()
{
brt=0;
long long ccf=1;
if(st.empty()) return query(1, 0, n-1, 0, n-1);
set<int>::iterator it=st.begin();
while(it!=st.end())
{
spc[brt]=-(*it);
cf[brt]=a[-(*it)];
brt++;
ccf*=a[-(*it)];
it++;
if(ccf>1e9) break;
}
reverse(spc, spc+brt);
reverse(cf, cf+brt);
long long ans=0, id=0;
if(ccf<=1e9) ans=query(1, 0, n-1, 0, n-1);
long long rc=1;
for(int i=0; i<brt; i++)
{
if(i || ccf<=1e9) rc*=cf[i];
long long tz=query(1, 0, n-1, spc[i], n-1);
if(ans<tz*rc) ans=tz*rc;
}
if(ccf<=1e9) return ans%mod;
return ((ans%mod)*query2(1, 0, n-1, 0, spc[0]))%mod;
}
int init(int N, int X[], int Y[])
{
n=N;
for(int i=0; i<n; i++)
{
update(1, 0, n-1, i, Y[i]);
update2(1, 0, n-1, i, X[i]);
a[i]=X[i];
if(a[i]>1) st.insert(-i);
}
return solve();
}
int updateX(int pos, int val)
{
if(a[pos]==1 && val>1) st.insert(-pos);
else if(a[pos]>1 && val==1) st.erase(-pos);
update2(1, 0, n-1, pos, val);
a[pos]=val;
return solve();
}
int updateY(int pos, int val)
{
update(1, 0, n-1, pos, val);
return solve();
}
Compilation message
horses.cpp: In function 'long long int solve()':
horses.cpp:63:12: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
63 | if(ccf>1e9) break;
| ^~~
horses.cpp:68:8: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
68 | if(ccf<=1e9) ans=query(1, 0, n-1, 0, n-1);
| ^~~
horses.cpp:72:17: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
72 | if(i || ccf<=1e9) rc*=cf[i];
| ^~~
horses.cpp:76:8: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
76 | if(ccf<=1e9) return ans%mod;
| ^~~
horses.cpp:67:22: warning: unused variable 'id' [-Wunused-variable]
67 | long long ans=0, id=0;
| ^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:91:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
91 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:100:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
100 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:106:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
106 | return solve();
| ~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
328 KB |
Output is correct |
27 |
Correct |
3 ms |
372 KB |
Output is correct |
28 |
Correct |
2 ms |
328 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
595 ms |
43152 KB |
Output is correct |
2 |
Correct |
385 ms |
42956 KB |
Output is correct |
3 |
Correct |
345 ms |
46760 KB |
Output is correct |
4 |
Correct |
368 ms |
50572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
324 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
328 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
167 ms |
22616 KB |
Output is correct |
34 |
Correct |
169 ms |
22604 KB |
Output is correct |
35 |
Correct |
286 ms |
52936 KB |
Output is correct |
36 |
Correct |
255 ms |
52768 KB |
Output is correct |
37 |
Correct |
192 ms |
20784 KB |
Output is correct |
38 |
Correct |
203 ms |
33552 KB |
Output is correct |
39 |
Correct |
156 ms |
20524 KB |
Output is correct |
40 |
Correct |
248 ms |
47980 KB |
Output is correct |
41 |
Correct |
175 ms |
20556 KB |
Output is correct |
42 |
Correct |
194 ms |
20584 KB |
Output is correct |
43 |
Correct |
234 ms |
48336 KB |
Output is correct |
44 |
Correct |
258 ms |
48248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
388 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
613 ms |
46720 KB |
Output is correct |
34 |
Correct |
345 ms |
55504 KB |
Output is correct |
35 |
Correct |
338 ms |
46628 KB |
Output is correct |
36 |
Correct |
387 ms |
50696 KB |
Output is correct |
37 |
Correct |
165 ms |
22604 KB |
Output is correct |
38 |
Correct |
168 ms |
22616 KB |
Output is correct |
39 |
Correct |
291 ms |
52928 KB |
Output is correct |
40 |
Correct |
264 ms |
52864 KB |
Output is correct |
41 |
Correct |
187 ms |
20776 KB |
Output is correct |
42 |
Correct |
271 ms |
33544 KB |
Output is correct |
43 |
Correct |
157 ms |
20520 KB |
Output is correct |
44 |
Correct |
254 ms |
47996 KB |
Output is correct |
45 |
Correct |
203 ms |
20552 KB |
Output is correct |
46 |
Correct |
185 ms |
20580 KB |
Output is correct |
47 |
Correct |
258 ms |
48332 KB |
Output is correct |
48 |
Correct |
233 ms |
48284 KB |
Output is correct |
49 |
Correct |
279 ms |
25612 KB |
Output is correct |
50 |
Correct |
272 ms |
25616 KB |
Output is correct |
51 |
Correct |
388 ms |
54804 KB |
Output is correct |
52 |
Correct |
365 ms |
54280 KB |
Output is correct |
53 |
Correct |
542 ms |
23924 KB |
Output is correct |
54 |
Correct |
373 ms |
37424 KB |
Output is correct |
55 |
Correct |
218 ms |
21628 KB |
Output is correct |
56 |
Correct |
358 ms |
49688 KB |
Output is correct |
57 |
Correct |
418 ms |
22248 KB |
Output is correct |
58 |
Correct |
557 ms |
22648 KB |
Output is correct |
59 |
Correct |
251 ms |
48272 KB |
Output is correct |