Submission #375036

#TimeUsernameProblemLanguageResultExecution timeMemory
375036ijxjdjdSalesman (IOI09_salesman)C++14
0 / 100
250 ms65540 KiB
#include <bits/stdc++.h> #define FR(i, N) for (int i = 0; i < int(N); i++) #define all(x) begin(x), end(x) using namespace std; using ll = long long; #define int ll const int MAXN = (int)(5e5) + 5; const int INF = (int)(2e9); vector<pair<int, int>> byTime[MAXN]; int N, U, D, S; int segDirect[2][4*MAXN]; int segBack[2][4*MAXN]; void pull(int n) { for (int j = 0; j < 2; j++) { segDirect[j][n] = max(segDirect[j][2*n], segDirect[j][2*n+1]); segBack[j][n] = max(segBack[j][2*n], segBack[j][2*n+1]); } } pair<int, int> query(int l, int r, bool right, int n = 1, int tl = 0, int tr = MAXN-1) { if (l > tr || r < tl) { return {-INF, -INF}; } else if (l <= tl && tr <= r) { return {segDirect[right][n], segBack[right][n]}; } else { int tm = (tl + tr)/2; auto p1 = query(l, r, right, 2*n, tl, tm); auto p2 = query(l, r, right, 2*n+1, tm+1, tr); return {max(p1.first, p2.first), max(p1.second, p2.second)}; } } void upd(int i, int val, int n = 1, int tl = 0, int tr = MAXN-1) { if (tl == tr) { segBack[1][n] = val-U*i; segDirect[1][n] = val-U*i+i*(U+D); segBack[0][n] = val+D*i; segDirect[0][n] = val+D*i-i*(D+U); } else { int tm = (tl + tr)/2; if (i <= tm) { upd(i, val, 2*n, tl, tm); } else { upd(i, val, 2*n+1, tm+1, tr); } pull(n); } } signed main() { cin.tie(0); cin.sync_with_stdio(0); cin >> N >> U >> D >> S; for (int i = 0; i < N; i++) { int T, L, K; cin >> T >> L >> K; byTime[T].push_back({L, K}); } for (int i = 0; i < 4*MAXN; i++) { segBack[0][i] = -INF; segBack[1][i] = -INF; segDirect[0][i] = -INF; segDirect[1][i] = -INF; } int ans = -INF; upd(S, 0); for (auto& t : byTime) { sort(all(t)); vector<int> res(t.size(), -INF); int curDirect = -INF; int curBack = -INF; int backKeep = -INF; int lst = MAXN; for (int i = int(t.size())-1; i>=0; i--) { auto qs = query(t[i].first, lst-1, false); curDirect = max(curDirect, qs.first) + t[i].second; curBack = max(curBack, backKeep + qs.second); res[i] = max(res[i], curDirect+U*t[i].first); res[i] = max(res[i], curBack+U*t[i].first+t[i].second); backKeep = max(backKeep, -t[i].first*(D+U)); backKeep += t[i].second; curBack += t[i].second; lst = t[i].first; } curDirect = -INF; curBack = -INF; backKeep = -INF; lst = -1; for (int i = 0; i < t.size(); i++) { auto qs = query(lst+1, t[i].first, true); curDirect = max(curDirect, qs.first) + t[i].second; curBack = max(curBack, backKeep + qs.second); res[i] = max(res[i], curDirect - D*t[i].first); res[i] = max(res[i], curBack - D*t[i].first + t[i].second); backKeep = max(backKeep, t[i].first*(D+U)); backKeep += t[i].second; curBack += t[i].second; lst = t[i].first; } for (int i = 0; i < t.size(); i++) { if (t[i].first < S) { ans = max(ans, res[i] - (S-t[i].first)*D); } else { ans = max(ans, res[i] - (t[i].first-S)*U); } upd(t[i].first, res[i]); } } cout << ans << '\n'; return 0; }

Compilation message (stderr)

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