Submission #484935

# Submission time Handle Problem Language Result Execution time Memory
484935 2021-11-05T18:24:55 Z Bench0310 Hotel (CEOI11_hot) C++17
10 / 100
573 ms 92732 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

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

void apply(int idx,ll 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,ll 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<<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--)
    {
        ll mx=tree[1];
        if(mx<0) break;
        res+=mx;
        int i=descend(1,1,n);
        int d=(-v[i].back()+v[i][(int)v[i].size()-2]);
        update(1,1,n,i,i,d);
        v[i].pop_back();
        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 14 ms 31564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 31564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 31648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 31548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 32836 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 36520 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 136 ms 40248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 418 ms 56412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 531 ms 80784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 573 ms 92732 KB Output isn't correct
2 Halted 0 ms 0 KB -