제출 #649577

#제출 시각아이디문제언어결과실행 시간메모리
649577KoalaMuchSalesman (IOI09_salesman)C++14
100 / 100
1889 ms52072 KiB
#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] = -4e9+l*d; sm[now][1] = -4e9-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 -5e9; 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,500001,1,u,d); update(1,500001,s,1,s*d,0,false); update(1,500001,s,1,-s*u,1,false); for(long long i=1;i<=500001;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,500001,loc,loc,1,0)-loc*d; long long fromd = query(1,500001,1,loc,1,0)+pro-loc*d,fromu = query(1,500001,loc,500001,1,1)+pro+loc*u; long long bestV = max(fromu,fromd); can[loc] = bestV; //if(loc==80) cout << fromd << " " << fromu << " " << query(1,500001,loc,500001,1,1) << "\n"; update(1,500001,loc,1,bestV+d*loc,0,false); update(1,500001,loc,1,bestV-u*loc,1,false); } for(long long j=0;j<fair[i].size();j++){ loc = fair[i][j].first; update(1,500001,loc,1,old[loc]+d*loc,0,true); update(1,500001,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,500001,1,loc,1,0)+pro-loc*d,fromu = query(1,500001,loc,500001,1,1)+pro+loc*u; long long bestV = max(fromu,fromd); can[loc] = max(can[loc],bestV); update(1,500001,loc,1,bestV+d*loc,0,false); update(1,500001,loc,1,bestV-u*loc,1,false); } for(long long j=0;j<fair[i].size();j++){ loc = fair[i][j].first; update(1,500001,loc,1,can[loc]+d*loc,0,false); update(1,500001,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) 메시지

salesman.cpp: In function 'int main()':
salesman.cpp:51:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(long long j=0;j<fair[i].size();j++){
      |                           ~^~~~~~~~~~~~~~~
salesman.cpp:61:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for(long long j=0;j<fair[i].size();j++){
      |                           ~^~~~~~~~~~~~~~~
salesman.cpp:74:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for(long long j=0;j<fair[i].size();j++){
      |                           ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...