Submission #556996

#TimeUsernameProblemLanguageResultExecution timeMemory
556996timreizinSalesman (IOI09_salesman)C++17
100 / 100
1042 ms59076 KiB
#include <iostream> #include <vector> #include <algorithm> #include <deque> #include <set> #include <string> #include <numeric> #include <cmath> #include <cassert> #include <array> #include <numeric> using namespace std; using ll = long long; class SegmentTree { private: int amount; vector<ll> tree; ll get(int a, int b, int l, int r, int v) { if (a > r || b < l) return -1e9; if (a == l && b == r) return tree[v]; int m = (l + r) >> 1; return max(get(a, min(b, m), l, m, v << 1), get(max(a, m + 1), b, m + 1, r, (v << 1) + 1)); } void build(int l, int r, int v) { if (l > r) return; if (l == r) { tree[v] = -1e9; return; } int m = (l + r) >> 1; build(l, m, v << 1); build(m + 1, r, (v << 1) + 1); tree[v] = max(tree[v << 1], tree[(v << 1) + 1]); } void update(int p, int l, int r, int v, ll value) { if (l > r) return; if (l == r) { tree[v] = value; return; } int m = (l + r) >> 1; if (p <= m) update(p, l, m, v << 1, value); else update(p, m + 1, r, (v << 1) + 1, value); tree[v] = max(tree[v << 1], tree[(v << 1) + 1]); } public: SegmentTree(int n = 0) : amount(n) { tree.resize(4 * amount + 5); build(0, n - 1, 1); } ll get(int a, int b) { return get(a, b, 0, amount - 1, 1); } void update(int p, ll value) { update(p, 0, amount - 1, 1, value); } }; int main() { cin.tie(0)->sync_with_stdio(0); int n; ll d, u, s; cin >> n >> u >> d >> s; vector<tuple<int, ll, ll>> fairs(n); for (auto &[t, l, m] : fairs) cin >> t >> l >> m; sort(fairs.begin(), fairs.end()); vector<vector<pair<ll, ll>>> times; int last = get<0>(fairs.front()); times.push_back(vector<pair<ll, ll>>()); for (auto [t, l, m] : fairs) { if (t != last) times.push_back(vector<pair<ll, ll>>()); times.back().emplace_back(l, m); last = t; } vector<tuple<int, ll, ll>>().swap(fairs); ll res = 0; SegmentTree left(500002), right(500002); left.update(s, s * d); right.update(s, -s * u); for (auto &fairs : times) { vector<ll> dp(fairs.size(), -1e9); ll delta = 0, prev = fairs[0].first; set<ll> best; for (int i = 0; i < dp.size(); ++i) { delta -= d * (fairs[i].first - prev); best.insert(max(left.get(0, fairs[i].first) - d * fairs[i].first, right.get(fairs[i].first, 500001) + u * fairs[i].first) - delta); delta += fairs[i].second; prev = fairs[i].first; dp[i] = (*best.rbegin()) + delta; } delta = 0; prev = fairs.back().first; best.clear(); for (int i = (int)dp.size() - 1; i >= 0; --i) { delta -= u * (prev - fairs[i].first); best.insert(max(left.get(0, fairs[i].first) - d * fairs[i].first, right.get(fairs[i].first, 500001) + u * fairs[i].first) - delta); delta += fairs[i].second; prev = fairs[i].first; dp[i] = max(dp[i], (*best.rbegin()) + delta); } for (int i = 0; i < dp.size(); ++i) { ll move = (s < fairs[i].first ? u * (fairs[i].first - s) : d * (s - fairs[i].first)); res = max(res, dp[i] - move); left.update(fairs[i].first, dp[i] + fairs[i].first * d); right.update(fairs[i].first, dp[i] - fairs[i].first * u); } } cout << res; return 0; }

Compilation message (stderr)

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