162892025-04-20 17:39:58horkaMágikus táblázatcpp17Elfogadva 100/100305ms13452 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,m; cin>>n>>m;
    vector<int> a(n+1),b(m+1),pontok{(int)-1e9-10};
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        pontok.pb(a[i]);
    }
    for(int i=1; i<=m; i++)
    {
        cin>>b[i];
        pontok.pb(b[i]);
    }
    sort(all(pontok));
    pontok.erase(unique(all(pontok)),pontok.end());
    for(int i=1; i<=n; i++)
    {
        a[i]=lower_bound(all(pontok),a[i])-pontok.begin();
    }
    for(int i=1; i<=m; i++)
        b[i]=lower_bound(all(pontok),b[i])-pontok.begin();
    vector<array<int, 2>> op;
    for(int i=1; i<=m; i++)
        op.pb({b[i],i});
    sort(all(op));
    int mer=sz(pontok);
    vector<int> maxi(mer);
    set<int> s;
    for(int i=0; i<=m+1; i++)
        s.insert(i);
    for(auto &[ert,ind]:op)
    {
        s.erase(ind);
        auto l=s.lower_bound(ind),r=s.upper_bound(ind);
        l=prev(l);
        maxi[ert]=max(maxi[ert],*r-*l-1);
        //cout<<"itt: "<<ert<<" "<<ind<<" "<<*l<<" "<<*r<<endl;
    }
    for(int i=1; i<mer; i++)
        maxi[i]=max(maxi[i],maxi[i-1]);
    int ans=0;
    op.clear();
    for(int i=1; i<=n; i++)
        op.pb({a[i],i});
    sort(rall(op));
    s.clear();
    for(int i=0; i<=n+1; i++)
        s.insert(i);
    for(auto &[ert,ind]:op)
    {
        s.erase(ind);
        auto l=s.lower_bound(ind),r=s.upper_bound(ind);
        l=prev(l);
        ans=max(ans,(*r-*l-1)*maxi[ert]);
    }
    cout<<ans<<"\n";
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva1ms316 KiB
2Elfogadva23ms1588 KiB
subtask214/14
3Elfogadva1ms316 KiB
4Elfogadva1ms316 KiB
5Elfogadva1ms500 KiB
6Elfogadva1ms316 KiB
7Elfogadva1ms316 KiB
8Elfogadva1ms316 KiB
subtask327/27
9Elfogadva4ms520 KiB
10Elfogadva4ms544 KiB
11Elfogadva4ms552 KiB
12Elfogadva4ms856 KiB
13Elfogadva3ms424 KiB
14Elfogadva2ms500 KiB
15Elfogadva3ms564 KiB
16Elfogadva4ms564 KiB
17Elfogadva4ms676 KiB
subtask421/21
18Elfogadva245ms10532 KiB
19Elfogadva240ms10660 KiB
20Elfogadva165ms10528 KiB
21Elfogadva159ms10660 KiB
22Elfogadva143ms9252 KiB
23Elfogadva143ms9252 KiB
24Elfogadva3ms564 KiB
subtask538/38
25Elfogadva305ms13348 KiB
26Elfogadva296ms13452 KiB
27Elfogadva301ms13348 KiB
28Elfogadva294ms13348 KiB
29Elfogadva212ms12676 KiB
30Elfogadva226ms12436 KiB
31Elfogadva172ms12332 KiB
32Elfogadva180ms8740 KiB
33Elfogadva175ms8740 KiB
34Elfogadva97ms7716 KiB
35Elfogadva148ms7972 KiB
36Elfogadva232ms12840 KiB
37Elfogadva233ms12580 KiB
38Elfogadva219ms12580 KiB
39Elfogadva296ms13348 KiB
40Elfogadva279ms13092 KiB
41Elfogadva231ms11300 KiB
42Elfogadva212ms12068 KiB
43Elfogadva177ms12324 KiB
44Elfogadva196ms12584 KiB