This commit is contained in:
Zengtudor 2024-11-18 15:43:54 +08:00
parent 0db4cafb56
commit 1a9419d0b8
3 changed files with 55 additions and 24 deletions

View File

@ -3,45 +3,30 @@
#include <iostream>
#include <set>
using ll=int64_t;
using ll = int64_t;
using std::cin, std::cout;
const ll maxn=1e5+5;
ll t, n, a[maxn], inf=(1l<<(sizeof(inf)*8-5)), ninf=-inf;
const ll maxn = 1e5+5;
ll t, n, a[maxn], ans, inf=(1l<<(sizeof(inf)*8-4));
int main(){
std::iostream::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cin>>t;
while(t--){
std::multiset<ll> rset, lset;
ans = -inf;
cin>>n;
std::multiset<ll> lset, rset;
for(ll i{1};i<=n;i++){
cin>>a[i];
rset.emplace(a[i]);
}
rset.erase(rset.find(a[1]));
lset.emplace(a[1]);
ll ans{ninf};
for(ll j{2};j<n;j++){
rset.erase(rset.find(a[j]));
auto lit {lset.lower_bound(a[j])};
decltype(rset.end()) rit;
if(lit==lset.end())lit--;
while(*lit>=a[j]){
if(lit==lset.begin())goto end;
--lit;
}
if(lit==lset.end() || (*lit)>=a[j])goto end;
rit = rset.end();
--rit;
if(*rit<=a[j])goto end;
ans=std::max(ans, (*lit) * a[j] * (*rit));
end:;
lset.emplace(a[j]);
for(ll i{2};i<n;i++){
lset.emplace(a[i]);
}
cout<<(ans==ninf?-1:ans)<<'\n';
// cout<<ans<<'\n';
cout<<(ans==-inf?-1:ans)<<'\n';
}
}

View File

@ -0,0 +1,18 @@
#include <cstdint>
#include <iostream>
#include <random>
using ll = int64_t;
using std::cin, std::cout;
const ll inf = (1l<<32);
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';
}
}

View File

@ -0,0 +1,28 @@
#include <algorithm>
#include <cstdint>
#include <iostream>
using ll = int64_t;
using std::cin, std::cout;
const ll maxn = 1e5+5;
ll t, n, a[maxn], ans, inf=(1l<<(sizeof(inf)*8-4));
int main(){
std::iostream::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cin>>t;
while(t--){
ans = -inf;
cin>>n;
for(ll i{1};i<=n;i++)cin>>a[i];
for(ll i{1};i<n-1;i++)
for(ll j{i+1};j<n;j++)
for(ll k{j+1};k<=n;k++){
if(a[i]<a[j] && a[j]<a[k]){
ans=std::max(ans, a[i]*a[j]*a[k]);
}
}
cout<<(ans==-inf?-1:ans)<<'\n';
}
}