This commit is contained in:
Zengtudor 2024-11-18 18:04:06 +08:00
parent 1a9419d0b8
commit 195b2065c5
3 changed files with 92 additions and 8 deletions

View File

@ -1,3 +1,42 @@
/*
100pts but hack
in:
10
7
41 20 50 18 25 -23 -32
10
8 35 -49 49 -27 8 33 8 36 16
5
-16 4 -17 -38 -25
8
-12 -7 -47 4 42 30 4 -36
8
-17 -3 15 -7 -27 -35 17 35
10
-6 49 -21 49 47 20 17 41 -39 27
8
2 44 36 -45 -8 -15 -9 16
10
1 33 -15 11 15 -10 19 -42 37 -5
6
40 19 45 -28 34 42
8
10 5 4 -47 -7 -37 23 21
ans:
-1 -1
47628 47628
-1 -1
3528 3528
8925 8925
-4182 <-failed -2754 <-pass
10800 10800
10545 10545
27132 27132
39997 39997
*/
#include <algorithm>
#include <cstdint>
#include <iostream>
@ -21,10 +60,47 @@ int main(){
cin>>a[i];
rset.emplace(a[i]);
}
rset.erase(rset.find(a[1]));
// if(auto it{rset.find(a[1])};it!=rset.end())[[likely]]{
rset.erase(rset.find(a[1]));
// }else{
// throw std::runtime_error("unreachable");
// }
lset.emplace(a[1]);
for(ll i{2};i<n;i++){
rset.erase(rset.find(a[i]));
// if(a[i]==0){
// ans=std::max(a[i], 0l);
// continue;
// }
// cout<<*lset.rbegin()<<' '<<a[i]<<' '<<*rset.rbegin()<<'\n';
const auto check_ans = [](const ll &a, const ll &b, const ll &c)->void{
// cout<<a<<' '<<b<<' '<<c<<'\n';
if(a<b&&b<c){
ans=std::max(ans,a*b*c);
}
};
{
auto lit = lset.lower_bound(a[i]);
if(lit==lset.end())--lit;
while(*lit>=a[i]){
if(lit==lset.begin())goto out;
--lit;
}
if(lit!=lset.end()){
check_ans(*lit, a[i], *rset.rbegin());
}
}
out:;
{
if(auto it = rset.lower_bound(a[i]);it!=rset.end()){
check_ans(*lset.begin() , a[i], *it);
}
}
//-8 -4 10
check_ans(*lset.begin(),a[i],*rset.rbegin());
lset.emplace(a[i]);
}
cout<<(ans==-inf?-1:ans)<<'\n';

View File

@ -3,16 +3,24 @@
#include <random>
using ll = int64_t;
using std::cin, std::cout;
using std::cout;
const ll inf = (1l<<32);
const ll inf = 20;
int main(){
std::random_device rd;
std::mt19937_64 mt{rd()};
std::uniform_int_distribution<ll> uid{-inf, inf};
ll t {100};
while (t--) {
cout<<uid(mt)<<'\n';
std::uniform_int_distribution<ll> uidn{5, inf};
auto t = uidn(mt);
cout<<t<<'\n';
while(t--){
ll n{uidn(mt)};
cout<<n<<'\n';
std::uniform_int_distribution<ll> uida{1,inf};
while(n--){
cout<<uida(mt)<<' ';
}
cout<<'\n';
}
}

View File

@ -47,6 +47,6 @@ int main(){
}
}
for(ll i{1};i<=k;i++){
cout<<(mkd[i]==inf?0:mkd[i])<<'\n';
cout<<(mkd[i]==inf?-1:mkd[i])<<'\n';
}
}