# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
649574 | KoalaMuch | Salesman (IOI09_salesman) | C++14 | 2023 ms | 60904 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+4;
long long sm[N*4][2];
vector<pair<long long,long long>> fair[N];
long long old[N];
long long can[N];
void build(long long l,long long r,long long now,long long u,long long d){
if(l==r){
sm[now][0] = -2e9+l*d;
sm[now][1] = -2e9-l*u;
return ;
}
long long mid = (l+r) >> 1;
build(l,mid,now<<1,u,d),build(mid+1,r,now<<1|1,u,d);
sm[now][0] = max(sm[now<<1][0],sm[now<<1|1][0]);
sm[now][1] = max(sm[now<<1][1],sm[now<<1|1][1]);
}
void update(long long l,long long r,long long id,long long now,long long v,long long t,bool rep){
if(l>id||r<id) return ;
if(l==r){
if(!rep) sm[now][t] = max(sm[now][t],v);
else sm[now][t] = v;
return ;
}
long long mid = (l+r) >> 1;
update(l,mid,id,now<<1,v,t,rep),update(mid+1,r,id,now<<1|1,v,t,rep);
sm[now][t] = max(sm[now<<1][t],sm[now<<1|1][t]);
}
long long query(long long l,long long r,long long ll,long long rr,long long now,long long t){
if(l>rr||r<ll) return -2e9;
if(l>=ll&&r<=rr) return sm[now][t];
long long mid = (l+r) >> 1;
return max(query(l,mid,ll,rr,now<<1,t),query(mid+1,r,ll,rr,now<<1|1,t));
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n,u,d,s,day,loc,pro;
cin >> n >> u >> d >> s;
for(long long i=0;i<n;i++){
cin >> day >> loc >> pro;
fair[day].push_back({loc,pro});
}
long long ans = 0;
build(1,500000,1,u,d);
update(1,500000,s,1,s*d,0,false);
update(1,500000,s,1,-s*u,1,false);
for(long long i=1;i<=500000;i++){
sort(fair[i].begin(),fair[i].end());
for(long long j=0;j<fair[i].size();j++){
loc = fair[i][j].first,pro = fair[i][j].second;
old[loc] = query(1,500000,loc,loc,1,0)-loc*d;
long long fromd = query(1,500000,1,loc,1,0)+pro-loc*d,fromu = query(1,500000,loc,500000,1,1)+pro+loc*u;
long long bestV = max(fromu,fromd);
can[loc] = bestV;
//if(loc==80) cout << fromd << " " << fromu << " " << query(1,500000,loc,500000,1,1) << "\n";
update(1,500000,loc,1,bestV+d*loc,0,false);
update(1,500000,loc,1,bestV-u*loc,1,false);
}
for(long long j=0;j<fair[i].size();j++){
loc = fair[i][j].first;
update(1,500000,loc,1,old[loc]+d*loc,0,true);
update(1,500000,loc,1,old[loc]-u*loc,1,true);
}
for(long long j=fair[i].size()-1;j>=0;j--){
loc = fair[i][j].first,pro=fair[i][j].second;
long long fromd = query(1,500000,1,loc,1,0)+pro-loc*d,fromu = query(1,500000,loc,500000,1,1)+pro+loc*u;
long long bestV = max(fromu,fromd);
can[loc] = max(can[loc],bestV);
update(1,500000,loc,1,bestV+d*loc,0,false);
update(1,500000,loc,1,bestV-u*loc,1,false);
}
for(long long j=0;j<fair[i].size();j++){
loc = fair[i][j].first;
update(1,500000,loc,1,can[loc]+d*loc,0,false);
update(1,500000,loc,1,can[loc]-u*loc,1,false);
if(loc<s) ans = max(ans,can[loc]-d*(s-loc));
else ans = max(ans,can[loc]-u*(loc-s));
}
//if(fair[i].size()) cout << ans << "\n";
}
cout << ans << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |