Submission #861955

#TimeUsernameProblemLanguageResultExecution timeMemory
86195512345678Salesman (IOI09_salesman)C++17
60 / 100
616 ms39392 KiB
#include <bits/stdc++.h> using namespace std; const int nx=5e5+5; int n, u, d, s, x, y, z; vector<pair<int, int>> t[nx]; struct segtree { int d[4*nx]; void build(int l, int r, int i) { if (l==r) return void(d[i]=-2e9); int md=(l+r)/2; build(l, md, 2*i); build(md+1, r, 2*i+1); d[i]=max(d[2*i], d[2*i+1]); } void update(int l, int r, int i, int idx, int vl) { if (idx<l||r<idx) return; if (l==r) return void(d[i]=max(d[i], vl)); int md=(l+r)/2; update(l, md, 2*i, idx, vl); update(md+1, r, 2*i+1, idx, vl); d[i]=max(d[2*i], d[2*i+1]); } int query(int l, int r, int i, int ql, int qr) { if (r<ql||qr<l) return INT_MIN; if (ql<=l&&r<=qr) return d[i]; int md=(l+r)/2; return max(query(l, md, 2*i, ql, qr), query(md+1, r, 2*i+1, ql, qr)); } } up, dn; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>u>>d>>s; for (int i=0; i<n; i++) cin>>x>>y>>z, t[x].push_back({y, z}); up.build(1, nx-1, 1); dn.build(1, nx-1, 1); up.update(1, nx-1, 1, s, -s*u); dn.update(1, nx-1, 1, s, s*d); for (int i=1; i<nx; i++) { sort(t[i].begin(), t[i].end()); vector<int> tmp(t[i].size()), rtmp(t[i].size()); for (int j=0; j<t[i].size(); j++) { int y=t[i][j].first, z=t[i][j].second; int qup=up.query(1, nx-1, 1, y, nx-1); int qdn=dn.query(1, nx-1, 1, 1, y); int mx=max(qup+y*u, qdn-y*d)+z; if (j>=1) mx=max(mx, tmp[j-1]+(y-t[i][j-1].first)*d+z); tmp[j]=mx; } for (int j=t[i].size()-1; j>=0; j--) { int y=t[i][j].first, z=t[i][j].second; int qup=up.query(1, nx-1, 1, y, nx-1); int qdn=dn.query(1, nx-1, 1, 1, y); int mx=max(qup+y*u, qdn-y*d)+z; if (j<=((int)t[i].size()-2)) mx=max(mx, rtmp[j+1]+(t[i][j+1].first-y)*u+z); //cout<<"here2 "<<y<<' '<<z<<' '<<mx<<'\n'; rtmp[j]=mx; } for (int j=0; j<t[i].size(); j++) { int y=t[i][j].first; up.update(1, nx-1, 1, y, max(tmp[j], rtmp[j])-y*u); dn.update(1, nx-1, 1, y, max(tmp[j], rtmp[j])+y*d); } } cout<<max(up.query(1, nx-1, 1, s, nx-1)+s*u, dn.query(1, nx-1, 1, 1, s)-s*d); }

Compilation message (stderr)

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