Submission #484947

# Submission time Handle Problem Language Result Execution time Memory
484947 2021-11-05T18:57:25 Z Bench0310 Hotel (CEOI11_hot) C++17
100 / 100
1681 ms 57376 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N=500005;
vector<int> tree(4*N,0);
vector<int> lazy(4*N,0);

void pull(int idx)
{
    tree[idx]=max(tree[2*idx],tree[2*idx+1]);
}

void apply(int idx,int x)
{
    tree[idx]+=x;
    lazy[idx]+=x;
}

void push(int idx)
{
    for(int i=0;i<2;i++) apply(2*idx+i,lazy[idx]);
    lazy[idx]=0;
}

void update(int idx,int l,int r,int ql,int qr,int x)
{
    if(ql>qr) return;
    if(l==ql&&r==qr) apply(idx,x);
    else
    {
        int m=(l+r)/2;
        push(idx);
        update(2*idx,l,m,ql,min(qr,m),x);
        update(2*idx+1,m+1,r,max(ql,m+1),qr,x);
        pull(idx);
    }
}

int descend(int idx,int l,int r)
{
    if(l==r) return l;
    int m=(l+r)/2;
    push(idx);
    if(tree[2*idx]>=tree[2*idx+1]) return descend(2*idx,l,m);
    else return descend(2*idx+1,m+1,r);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m,o;
    cin >> n >> m >> o;
    vector<array<int,2>> ini(n+1,{0,0});
    for(int i=1;i<=n;i++) cin >> ini[i][1] >> ini[i][0];
    sort(ini.begin(),ini.end());
    vector<int> p(n+1,0);
    vector<int> c(n+2,0);
    c[n+1]=(1<<30);
    for(int i=1;i<=n;i++)
    {
        p[i]=ini[i][0];
        c[i]=ini[i][1];
    }
    vector<bool> vis(n+1,0);
    vector<array<int,2>> v;
    for(int i=1;i<=n;i++) v.push_back({i,0});
    for(int i=0;i<m;i++)
    {
        int x,d;
        cin >> x >> d;
        int t=(lower_bound(p.begin(),p.end(),d)-p.begin());
        if(t<=n) v.push_back({t,x});
    }
    sort(v.begin(),v.end());
    vector<int> idx(n+1,0);
    for(int i=0;i<(int)v.size();i++) idx[v[i][0]]=i;
    for(int i=1;i<=n;i++) update(1,1,n,i,i,v[idx[i]][1]-c[i]);
    set<int> s;
    for(int i=0;i<=n+1;i++) s.insert(i);
    auto prv=[&](int x)->int
    {
        auto it=s.lower_bound(x);
        return (*prev(it));
    };
    auto nxt=[&](int x)->int
    {
        auto it=s.lower_bound(x);
        return (*it);
    };
    ll res=0;
    while(o--)
    {
        int mx=tree[1];
        if(mx<0) break;
        res+=mx;
        int t=descend(1,1,n);
        int d=(-v[idx[t]][1]+v[idx[t]-1][1]);
        idx[t]--;
        update(1,1,n,t,t,d);
        int i=nxt(t);
        s.erase(i);
        int r=nxt(i);
        int l=prv(i);
        update(1,1,n,l+1,i,c[i]-c[r]);
    }
    cout << res << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15948 KB Output is correct
2 Correct 7 ms 15992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15948 KB Output is correct
2 Correct 7 ms 15976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15948 KB Output is correct
2 Correct 7 ms 15988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 16656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 19232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 21772 KB Output is correct
2 Correct 89 ms 21636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 445 ms 32440 KB Output is correct
2 Correct 154 ms 25128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 554 ms 49024 KB Output is correct
2 Correct 497 ms 49120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 618 ms 57124 KB Output is correct
2 Correct 1217 ms 57176 KB Output is correct
3 Correct 1681 ms 57376 KB Output is correct