Submission #667032

#TimeUsernameProblemLanguageResultExecution timeMemory
667032tatyamCatfish Farm (IOI22_fish)C++17
100 / 100
260 ms23208 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; void chmax(ll& a, ll b){ if(a < b) a = b; } // range chmax・1 点取得 で O(M log N) struct SegTree { ll n; vector<ll> seg; SegTree(ll n): n(n), seg(n * 2) {} void range_chmax(ll l, ll r, ll x) { l += n; r += n; while(l < r){ if(l & 1) chmax(seg[l++], x); if(r & 1) chmax(seg[--r], x); l >>= 1; r >>= 1; } } ll operator[](ll i) const { i += n; ll x = 0; do chmax(x, seg[i]); while(i >>= 1); return x; } }; ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) { vector fish(N, vector<pair<ll, ll>>{}); for (ll i = 0; i < M; i++) { fish[X[i]].emplace_back(Y[i], W[i]); } for (auto& v : fish) sort(v.begin(), v.end()); SegTree up(N + 1), down(N + 1); ll zero = 0; for(ll x = 0; x + 1 < N; x++) { for(auto [y, w] : fish[x]) { up.range_chmax(y + 1, N + 1, up[y] + w); } reverse(fish[x + 1].begin(), fish[x + 1].end()); for(auto [y, w] : fish[x + 1]) { down.range_chmax(0, y + 1, down[y + 1] + w); } reverse(fish[x + 1].begin(), fish[x + 1].end()); const ll zero_ = exchange(zero, down[0]); down.range_chmax(0, N + 1, max(up[N], zero_)); up.range_chmax(0, N + 1, zero_); } return max({zero, down[0], up[N]}); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...