Submission #935355

#TimeUsernameProblemLanguageResultExecution timeMemory
935355HuyQuang_re_ZeroMeetings (IOI18_meetings)C++14
36 / 100
536 ms257832 KiB
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define maxn 100005
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define IDB pair <db,int>
#define TII pair <treap*,treap*>
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x)
#include "meetings.h"
using namespace std;
const ll oo=round(1e18);
ll a[maxn],i,j,q,n,up[5005][5005],down[5005][5005];
struct pt
{
    int res,l,r,full;
    friend pt operator + (pt a,pt b)
    {
        pt c;
        c.res=max(max(a.res,b.res),a.r+b.l);
        c.l=a.l+(a.full ? b.l : 0);
        c.r=b.r+(b.full ? a.r : 0);
        c.full=a.full&b.full;
        return c;
    }
};
struct Interval_Tree
{
    pt st[4*maxn];
    void build(int id,int l,int r)
    {
        if(l==r)
        {
            if(a[l]==1) st[id]={ 1,1,1,1 };
            else st[id]={ 0,0,0,0 };
            return ;
        }
        int mid=(l+r)>>1;
        build(id*2,l,mid); build(id*2+1,mid+1,r);
        st[id]=st[id*2]+st[id*2+1];
    }
    pt get(int id,int l,int r,int u,int v)
    {
        if(u<=l && r<=v) return st[id];
        int mid=(l+r)>>1;
        if(v<=mid) return get(id*2,l,mid,u,v);
        if(u>mid) return get(id*2+1,mid+1,r,u,v);
        return get(id*2,l,mid,u,mid)+get(id*2+1,mid+1,r,mid+1,v);
    }
} IT;
vector <ll> minimum_costs(vector <int> h,vector <int> L,vector <int> R)
{
    for(int x:h) a[++n]=x;
    q=L.size();
    for(i=0;i<q;i++) L[i]++,R[i]++;
    vector <ll> res(q);
    if(n<=5000 && q<=5000)
    {
        for(i=1;i<=n;i++)
        {
            ll ma=0;
            for(j=i;j>=1;j--)
            {
                ma=max(ma,a[j]);
                down[i][j]=down[i][j+1]+ma;
            }

            ma=0;
            for(j=i;j<=n;j++)
            {
                ma=max(ma,a[j]);
                up[i][j]=up[i][j-1]+ma;
            }
        }

        for(i=0;i<q;i++)
        {
            int l=L[i],r=R[i];
            res[i]=oo;
            for(int u=l;u<=r;u++)
                res[i]=min(res[i],down[u][l]+up[u][r]-a[u]);
        }
    }
    else
    {
        IT.build(1,1,n);
        for(i=0;i<q;i++)
        {
            int l=L[i],r=R[i];
            res[i]=2*(r-l+1)-IT.get(1,1,n,l,r).res;
        }
    }
    return res;
}
/*
int main()
{
  //  freopen("meetings.inp","r",stdin);
    //freopen("meetings.out","w",stdout);
    vector <int> a,L,R;
    int k,n,l,r;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>k,a.push_back(k);
    while(cin>>l>>r) L.push_back(l),R.push_back(r);
    vector <ll> res=minimum_costs(a,L,R);
    for(int x:res) cout<<x<<'\n';
}

*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...