#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);
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:99:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
99 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:105:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
105 | return solve();
| ~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
312 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
312 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 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 |
1 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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
603 ms |
43012 KB |
Output is correct |
2 |
Incorrect |
318 ms |
43052 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
312 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 |
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 |
21 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
312 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 |
316 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 |
1 ms |
212 KB |
Output is correct |
21 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |