This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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<m;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);
auto iter = plans.begin();
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:58:14: warning: variable 'iter' set but not used [-Wunused-but-set-variable]
58 | auto iter = plans.begin();
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |