Submission #379314

#TimeUsernameProblemLanguageResultExecution timeMemory
379314ChrisTSalesman (IOI09_salesman)C++17
100 / 100
1478 ms65536 KiB
#include<bits/stdc++.h> using namespace std; const int MN = 5e5 + 5; struct Seg { long long tree[MN << 1]; int n; Seg() {n = MN; memset(tree,-0x3f,sizeof tree);} void update (int i, long long v) { for (tree[i += n-1] = v; i > 1; i >>= 1) tree[i>>1] = max(tree[i],tree[i^1]); } long long query (int l, int r) { long long ret = -1e18; for (l += n-1, r += n; l < r; l >>= 1, r >>= 1) { if (l&1) ret = max(ret,tree[l++]); if (r&1) ret = max(ret,tree[--r]); } return ret; } } segL, segR, segL2, segR2; vector<array<int,2>> atT[MN]; int main () { int n,u,d,s; scanf ("%d %d %d %d",&n,&u,&d,&s); while (n--) { int t,l,m; scanf ("%d %d %d",&t,&l,&m); atT[t].push_back({l,m}); } atT[MN-1].push_back({s,0}); segL.update(s,d * s); segR.update(s,-u*s); for (int t = 1; t < MN; t++) if (!atT[t].empty()) { int m = (int)atT[t].size(); vector<long long> dp1(m), dp2(m); sort(atT[t].begin(),atT[t].end()); for (int i = 0; i < m; i++) { auto [l,c] = atT[t][i]; dp1[i] = max(max(segL.query(1,l),segL2.query(1,l)) - d * l + c,max(segR.query(l,MN),segR2.query(l,MN)) + u * l + c); segL2.update(l,dp1[i] + d * l); segR2.update(l,dp1[i] - u * l); } for (int i = 0; i < m; i++) segL2.update(atT[t][i][0],-1e18), segR2.update(atT[t][i][0],-1e18); for (int i = m-1; i >= 0; i--) { auto [l,c] = atT[t][i]; dp2[i] = max(max(segL.query(1,l),segL2.query(1,l)) - d * l + c,max(segR.query(l,MN),segR2.query(l,MN)) + u * l + c); segL2.update(l,dp2[i] + d * l); segR2.update(l,dp2[i] - u * l); } for (int i = 0; i < m; i++) { auto [l,c] = atT[t][i]; segL2.update(l,-1e18); segR2.update(l,-1e18); segL.update(l,max(dp1[i],dp2[i]) + d * l); segR.update(l,max(dp1[i],dp2[i]) - u * l); } if (t + 1 == MN) return !printf ("%lld\n",dp1[0]); } return 0; }

Compilation message (stderr)

salesman.cpp: In function 'int main()':
salesman.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |  scanf ("%d %d %d %d",&n,&u,&d,&s);
      |  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
salesman.cpp:25:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |   int t,l,m; scanf ("%d %d %d",&t,&l,&m);
      |              ~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...