Submission #825008

#TimeUsernameProblemLanguageResultExecution timeMemory
825008becaidoCatfish Farm (IOI22_fish)C++17
3 / 100
246 ms28140 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifndef WAIMAI #include "fish.h" #endif #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const ll INF = 1e18; const int SIZE = 1e5 + 5; int n, m, R; vector<pair<int, int>> v[SIZE]; ll all[2], zero[2], fzero[2]; map<int, ll> inc[2], dek[2]; void chmax(ll &x, ll y) { x = max(x, y); } ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) { n = N; FOR (i, 0, M - 1) { X[i]++, Y[i]++; v[X[i]].pb(Y[i], W[i]); m = max(m, Y[i]); R = max(R, X[i] + 1); } R = min(R, n); all[0] = -INF; v[0].pb(0, 0), v[0].pb(m, 0); FOR (i, 1, R) { int f = i & 1; inc[f].clear(); dek[f].clear(); all[f] = zero[f] = fzero[f] = -INF; v[i].pb(0, 0), v[i].pb(m, 0); sort(v[i].begin(), v[i].end()); ll mx = zero[!f], sum = 0; auto it = inc[!f].begin(); for (auto [j, x] : v[i - 1]) { sum += x; if (inc[f].count(j)) chmax(inc[f][j], mx + sum); else inc[f][j] = mx + sum; while (it != inc[!f].end() && it->F <= j) chmax(mx, it->S - sum), it++; } mx = -INF; auto rit = dek[!f].rbegin(); reverse(v[i].begin(), v[i].end()); for (auto [j, x] : v[i]) { while (rit != dek[!f].rend() && rit->F >= j) chmax(mx, rit->S + sum), rit++; if (dek[f].count(j)) chmax(dek[f][j], mx - sum); else dek[f][j] = mx - sum; sum -= x; } reverse(v[i].begin(), v[i].end()); chmax(all[f], all[!f]); chmax(all[f], fzero[!f]); chmax(all[f], inc[f][m]); chmax(zero[f], zero[!f]); chmax(zero[f], fzero[!f]); chmax(fzero[f], dek[f][0]); chmax(dek[f][m], all[f]); // debug(i); // for (auto [j, val] : inc[f]) debug(j, val); // for (auto [j, val] : dek[f]) debug(j, val); } ll ans = 0; int f = R & 1; chmax(ans, zero[f]); chmax(ans, fzero[f]); chmax(ans, all[f]); return ans; } /* in1 5 4 0 2 5 1 1 2 4 4 1 3 3 3 out1 8 */ #ifdef WAIMAI int main() { int N, M; assert(2 == scanf("%d %d", &N, &M)); vector<int> X(M), Y(M), W(M); for (int i = 0; i < M; ++i) { assert(3 == scanf("%d %d %d", &X[i], &Y[i], &W[i])); } long long result = max_weights(N, M, X, Y, W); printf("%lld\n", result); return 0; } #endif
#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...