답안 #700369

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
700369 2023-02-19T05:48:37 Z LeVanThuc Discharging (NOI20_discharging) C++17
0 / 100
1000 ms 187800 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define p(x,y) pair<ll,ll>(x,y)
#define BIT(i,x) ((x>>i)&1)
#define MASK(x) (1<<x)
#define ld long double
#define __builtin_popcount __builtin_popcountll
#define pll pair<ll,ll>
template<class T1,class T2>
bool maximize(T1 &x,const T2 &y)
{
    if(x<y)
    {
        x=y;
        return 1;
    }
    return 0;
}
template<class T1,class T2>
bool minimize(T1 &x,const T2 &y)
{
    if(x>y)
    {
        x=y;
        return 1;
    }
    return 0;
}
void online()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
//    freopen("input.inp", "r", stdin);
//    freopen("output.out","w", stdout);
#else
#endif
}
static const ll N=1e6+10,M=1e16;
ll n,m,A,B,a[N][21],b[N],f[N],po[21];
ll rmq(ll l,ll r)
{
    ll z=log2(r-l);
    return max(a[l][z],a[r-po[z]+1][z]);
}
ll c(ll l,ll r)
{
    return rmq(l,r)*(n-l+1);
}
int main()
{
    online();
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i][0];
    }
    po[0]=1;
    for(int k=1;k<=19;k++) po[k]=po[k-1]*2;
    for(int j=1;j<=19;j++)
    for(int i=1;i+po[j]-1<=n;i++)
    {
        a[i][j]=max(a[i][j-1],a[i+po[j-1]][j-1]);
    }
    f[0]=0;
    deque<pll> vt;
    vt.emplace_back(0,0);
    ll ans=M;
    for(ll i=1;i<=n;i++)
    {
        while(vt.size()>=2&&vt[1].fi<=i) vt.pop_front();
        ll k=vt[0].se;
        f[i]=f[k]+c(k+1,i);
        for(ll j=vt.size()-1;j>=0;j--)
        {
            if(f[vt[j].se]+c(vt[j].se+1,vt[j].fi)>f[i]+c(i+1,vt[j].fi))
            {
                vt.pop_back();
            }
            else
            {
                ll b=vt[j].fi,d=n/2+1;
                 while(d)
                {
                    while(b+d<=n&&f[vt[j].se]+c(vt[j].se+1,b+d)<=f[i]+c(i+1,b+d)) b+=d;
                    d/=2;
                }
                b++;
                if(b!=n+1)
                {
                    vt.emplace_back(b,i);
                }
                break;
            }
        }
        if(vt.empty()) vt.emplace_back(1,i);
        for(auto v:vt) cout<<"("<<v.fi<<","<<v.se<<") ";
        cout<<f[i];
        cout<<'\n';
    }
    cout<<f[n];
}

Compilation message

Discharging.cpp: In function 'int main()':
Discharging.cpp:71:8: warning: unused variable 'ans' [-Wunused-variable]
   71 |     ll ans=M;
      |        ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1083 ms 187800 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -