제출 #921496

#제출 시각아이디문제언어결과실행 시간메모리
921496gs25Salesman (IOI09_salesman)C++17
21 / 100
3100 ms62324 KiB
#include <bits/stdc++.h> #define pb push_back #define all(v) (v).begin(), (v).end() #define rep(i, n) for (int i = 0; i < n; ++i) #define rrep(i, n) for (int i = 1; i <= n; ++i) #define ff first #define ss second using namespace std; typedef long long ll; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define dbg(x...) \ cerr << "\e[91m" << __func__ << ":" << __LINE__ << " [" << #x << "] = ["; \ _print(x); \ cerr << "\e[39m" << endl; #else #define dbg(x...) #endif int N,U,S,D; const int MAXN = 500010; vector<pair<int,int>> fuck[MAXN]; struct segment_tree{ int n; vector<int> seg; const int inf = 1e9; segment_tree(int x){ n = x+1; seg.resize(4*n+8,-inf); } void update(int node, int s, int e, int pos, int val){ if(pos<s||pos>e) return; if(s==e){ seg[node] = val; return; } int m = s+e>>1; update(2*node,s,m,pos,val); update(2*node+1,m+1,e,pos,val); seg[node] = max(seg[2*node],seg[2*node+1]); return; } int query(int node, int s, int e, int l, int r){ if(r<s||l>e) return -inf; if(l<=s&&e<=r) return seg[node]; int m = s+e>>1; return max(query(2*node,s,m,l,r),query(2*node+1,m+1,e,l,r)); } void update(int pos, int val){ return update(1,0,n,pos,val); } int query(int l, int r){ return query(1,0,n,l,r); } }; const int inf = 1e9; int bada(int pos, int M, segment_tree& seg1, segment_tree& seg2){ int lmax = M - D*pos + seg1.query(0,pos); int rmax = M + U*pos + seg2.query(pos,MAXN-1); dbg(lmax,rmax); int MM = max(lmax,rmax); //seg1.update(pos,MM+D*pos); //seg2.update(pos,MM-U*pos); return MM; } void solve(){ cin >> N >> U >> D >> S; rep(i,N){ int t,pos,M; cin >> t >> pos >> M; fuck[t].pb({pos,M}); } fuck[0].pb({S,0}); fuck[MAXN-1].pb({S,0}); segment_tree seg1(MAXN), seg2(MAXN); rep(i,N) sort(all(fuck[i])); seg1.update(S,D*S); seg2.update(S,-U*S); for(int i=1; i<MAXN; i++){ if(fuck[i].size()==0) continue; auto& vec = fuck[i]; int t = vec.size(); vector<int> tmp(t,0); for(int i=0;i<t;i++){ auto& [pos,M] = vec[i]; dbg(pos,M); tmp[i] = bada(pos,M,seg1,seg2); } for(int i=1; i<t; i++){ tmp[i] = max(tmp[i],tmp[i-1]-D*(vec[i].first - vec[i-1].first)); } for(int i=t-2;i>=0;i--){ tmp[i] = max(tmp[i],tmp[i+1]-U*(vec[i+1].first-vec[i].first)); } for(int i=0; i<t; i++){ auto& [pos,M] = vec[i]; dbg(tmp[i]); seg1.update(pos,tmp[i]+D*pos); seg2.update(pos,tmp[i]-U*pos); } } cout << seg1.query(S,S) - D*S; } int32_t main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t=1; //cin >> t; while(t--) solve(); }

컴파일 시 표준 에러 (stderr) 메시지

salesman.cpp: In member function 'void segment_tree::update(int, int, int, int, int)':
salesman.cpp:73:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   73 |   int m = s+e>>1;
      |           ~^~
salesman.cpp: In member function 'int segment_tree::query(int, int, int, int, int)':
salesman.cpp:83:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |   int m = s+e>>1;
      |           ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...