이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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";
}
컴파일 시 표준 에러 (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... |