#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*=a[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*=a[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 |
Incorrect |
1 ms |
248 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
622 ms |
46720 KB |
Output is correct |
2 |
Incorrect |
348 ms |
55508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |