Submission #627682

#TimeUsernameProblemLanguageResultExecution timeMemory
6276824123xr4323Catfish Farm (IOI22_fish)C++17
23 / 100
410 ms25644 KiB
#include <bits/stdc++.h> #define mp make_pair #define all(a) a.begin(),a.end() using namespace std; using pii = pair <long long, long long>; constexpr int maxn = 1e5 + 10; constexpr long long inf = 1e17 + 10; vector <pii> tree (maxn << 2, mp (0, -inf)); vector <pii> A (maxn << 2, mp (-inf, -inf)); inline void push (int v, int t_l, int t_r) { tree[v].first = max (tree[v].first, A[v].first); tree[v].second = max (tree[v].second, A[v].second); if (t_l != t_r) { A[v << 1].first = max (A[v << 1].first, A[v].first); A[v << 1].second = max (A[v << 1].second, A[v].second); A[v << 1 | 1].first = max (A[v << 1 | 1].first, A[v].first); A[v << 1 | 1].second = max (A[v << 1 | 1].second, A[v].second); } A[v] = mp (-inf, -inf); } inline void update (int l, int r, pii x, int v, int t_l, int t_r) { push (v, t_l, t_r); if (l > t_r || t_l > r) return; if (l <= t_l && t_r <= r) { A[v] = x; push (v, t_l, t_r); return; } int t_m = t_l + t_r >> 1; update (l, r, x, v << 1, t_l, t_m); update (l, r, x, v << 1 | 1, t_m + 1, t_r); tree[v].first = max (tree[v << 1].first, tree[v << 1 | 1].first); tree[v].second = max (tree[v << 1].second, tree[v << 1 | 1].second); } inline pii get (int i, int v, int t_l, int t_r) { if (i > t_r || t_l > i) return mp (-inf, -inf); push (v, t_l, t_r); if (t_l == t_r) return tree[v]; int t_m = t_l + t_r >> 1; return max (get (i, v << 1, t_l, t_m), get (i, v << 1 | 1, t_m + 1, t_r)); } vector <pii> pos [maxn]; long long last = 0; long long max_weights (int N, int M, vector <int> X, vector <int> Y, vector <int> W) { for (int i = 0; i < M; ++i) { pos[X[i] + 1].push_back (mp (Y[i] + 1, W[i])); } int n = N; for (int i = 1; i <= n; ++i) sort (all (pos[i])); for (int i = 1; i <= n; ++i) { for (pii j : pos[i]) { long long am = get (j.first, 1, 0, n).first + j.second; update (j.first + 1, n, mp (am, -inf), 1, 0, n); } for (int _j = (int) pos[i].size () - 1; _j >= 0; --_j) { pii j = pos[i][_j]; long long am = get (j.first, 1, 0, n).second + j.second; update (0, j.first - 1, mp (-inf, am), 1, 0, n); } long long to = get (n, 1, 0, n).first, from = get (0, 1, 0, n).second; update (0, n, mp (from, last), 1, 0, n); last = max (to, from); } return get (0, 1, 0, n).second; }

Compilation message (stderr)

fish.cpp: In function 'void update(int, int, pii, int, int, int)':
fish.cpp:32:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     int t_m = t_l + t_r >> 1;
      |               ~~~~^~~~~
fish.cpp: In function 'pii get(int, int, int, int)':
fish.cpp:43:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |     int t_m = t_l + t_r >> 1;
      |               ~~~~^~~~~
#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...