Submission #892895

#TimeUsernameProblemLanguageResultExecution timeMemory
892895Trisanu_DasCatfish Farm (IOI22_fish)C++17
100 / 100
250 ms25224 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; using ll = long long; vector<pair<int, int> > fishes[100005]; struct SegmentTree{ ll tree[1 << 18]; void init() { memset(tree, 0xcf, sizeof(tree)); } void upd(int idx, int s, int e, int l, int r, ll val) { if (e < l || r < s) return; if (l <= s && e <= r) { tree[idx] = max(tree[idx], val); return; } int mid = (s + e) / 2; upd(2 * idx, s, mid, l, r, val); upd(2 * idx + 1, mid + 1, e, l, r, val); } ll qry(int idx, int s, int e, int x) { if (s == e) return tree[idx]; int mid = (s + e) / 2; if (x <= mid) return max(tree[idx], qry(2 * idx, s, mid, x)); return max(tree[idx], qry(2 * idx + 1, mid + 1, e, x)); } } st_up, st_down; ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) { for (int i = 0; i < M; i++) fishes[X[i] + 1].push_back({Y[i] + 1, W[i]}); ll till_now = 0; st_down.init(); for (int i = 1; i <= N; i++) { sort(fishes[i].begin(), fishes[i].end()); for (auto [j, w] : fishes[i]) st_up.upd(1, 0, N + 1, j + 1, N + 1, st_up.qry(1, 0, N + 1, j) + w); reverse(fishes[i].begin(), fishes[i].end()); for (auto [j, w] : fishes[i]) st_down.upd(1, 0, N + 1, 0, j - 1, st_down.qry(1, 0, N + 1, j) + w); ll u_res = st_up.qry(1, 0, N + 1, N + 1), d_res = st_down.qry(1, 0, N + 1, 0); st_up.upd(1, 0, N + 1, 0, N + 1, d_res); st_down.upd(1, 0, N + 1, 0, N + 1, till_now); till_now = max(u_res, d_res); } return st_down.qry(1, 0, N + 1, 0); }
#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...