Submission #700245

# Submission time Handle Problem Language Result Execution time Memory
700245 2023-02-19T03:16:54 Z LeVanThuc Discharging (NOI20_discharging) C++11
9 / 100
87 ms 69276 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=2e5+10,M=1e16;
ll n,m,A,B,a[N],b[N],f[N];
struct SegmentTree
{
    vector<ll> Tree;
    ll n;
    SegmentTree(ll _n=0)
    {
        n=_n;
        Tree.resize(4*n+1);
    }
    ll update(ll i,ll l,ll r,ll pos,ll vl)
    {
        if(r<pos||pos<l) return Tree[i];
        if(l==r) return Tree[i]=vl;
        return Tree[i]=max(update(i*2,l,(l+r)/2,pos,vl),update(i*2+1,(l+r)/2+1,r,pos,vl));
    }
    ll query(ll i,ll l,ll r,ll l1,ll r1)
    {
        if(r1<l||r<l1) return 0;
        if(l1<=l&&r<=r1) return Tree[i];
        return max(query(i*2,l,(l+r)/2,l1,r1),query(i*2+1,(l+r)/2+1,r,l1,r1));
    }
}S;
ll c(ll l,ll r)
{
    return S.query(1,1,n,l,r)*(n-l+1);
}
int main()
{
    online();
    cin>>n;
    S=SegmentTree(n);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        S.update(1,1,n,i,a[i]);
    }
    f[0]=0;
    vector<pll> vt;
    vt.emplace_back(0,0);
    for(int i=1;i<=n;i++)
    {
        auto best=lower_bound(vt.begin(),vt.end(),p(i+1,0));
        best--;
        auto x=*best;
        ll k=x.se;
        f[i]=f[k]+c(k+1,i);
        for(int 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].se,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);
    }
    cout<<f[n];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 87 ms 69276 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 2 ms 340 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 2 ms 340 KB Output isn't correct
16 Halted 0 ms 0 KB -