Submission #484939

# Submission time Handle Problem Language Result Execution time Memory
484939 2021-11-05T18:42:50 Z Bench0310 Hotel (CEOI11_hot) C++17
100 / 100
1750 ms 78824 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<int> v[n+1];
    for(int i=1;i<=n;i++) v[i].push_back(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[t].push_back(x);
    }
    for(int i=1;i<=n;i++) sort(v[i].begin(),v[i].end());
    for(int i=1;i<=n;i++) update(1,1,n,i,i,v[i].back()-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[t].back()+v[t][(int)v[t].size()-2]);
        update(1,1,n,t,t,d);
        v[t].pop_back();
        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 7 ms 15948 KB Output is correct
2 Correct 7 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15948 KB Output is correct
2 Correct 7 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15948 KB Output is correct
2 Correct 8 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 17088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 20920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 24552 KB Output is correct
2 Correct 78 ms 24336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 432 ms 40636 KB Output is correct
2 Correct 143 ms 28800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 521 ms 65176 KB Output is correct
2 Correct 561 ms 64040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 574 ms 77080 KB Output is correct
2 Correct 1198 ms 77604 KB Output is correct
3 Correct 1750 ms 78824 KB Output is correct