Submission #1005703

#TimeUsernameProblemLanguageResultExecution timeMemory
1005703UnforgettableplTreatment Project (JOI20_treatment)C++17
100 / 100
628 ms129844 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
struct plan{
    int t,l,r,c;
    plan(int t,int l,int r,int c):t(t),l(l-1),r(r+1),c(c){}
    plan(int x):t(x),l(0),r(0),c(0){}
    bool operator<(const plan& other)const{
        return t-l<other.t-other.l;
    }
};

multiset<plan> tree[100001];

void add(int x,plan a){
    while(x<=100000){
        tree[x].insert(a);
        x+=x&-x;
    }
}

vector<plan> get(int x,int y){
    vector<plan> ans;
    while(x){
        while(tree[x].upper_bound(y)!=tree[x].end()){
            ans.emplace_back(*tree[x].upper_bound(y));
            tree[x].erase(tree[x].upper_bound(y));
        }
        x-=x&-x;
    }
    return ans;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vector<plan> plans;
    priority_queue<pair<int,plan>> q;
    for(int i=1;i<=m;i++){
        int t,l,r,c;cin>>t>>l>>r>>c;
        if(l==1) q.emplace(-c,plan(t,l,r,c));
        else plans.emplace_back(t,l,r,c);
    }
    sort(plans.begin(),plans.end(),[](const plan &a,const plan& b){return a.t+a.l<b.t+b.l;});
    for(int i=0;i<plans.size();i++)add(i+1,plans[i]);
    while(!q.empty()){
        auto [dist,curr] = q.top();q.pop();
        if(curr.r==n+1){
            cout << -dist << '\n';
            return 0;
        }
        auto idx = lower_bound(plans.begin(),plans.end(),curr.r+curr.t,[](const plan &a,const int &b){return a.t+a.l<b;})-plans.begin();
        auto goodplans = get(idx,curr.t-curr.r);
        for(plan&i:goodplans)q.emplace(dist-i.c,i);
    }
    cout << "-1\n";
}

Compilation message (stderr)

treatment.cpp: In function 'int32_t main()':
treatment.cpp:49:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<plan>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(int i=0;i<plans.size();i++)add(i+1,plans[i]);
      |                 ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...