Submission #1065370

#TimeUsernameProblemLanguageResultExecution timeMemory
1065370mc061The Big Prize (IOI17_prize)C++17
0 / 100
4 ms344 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5+6; bool is_worst[N]={}; bool know[N]={}; pair<int, int> val[N]; unordered_map<int, set<int, greater<int>>> last_by_sum; vector<int> ask(int i); pair<int, int> get(int i) { if (know[i]) { return val[i]; } know[i] = true; auto now = ask(i); last_by_sum[now[0] + now[1]].insert(i); return {now[0], now[1]}; } int find_best(int n) { int mx = 0; for (int i = 0; i < min(n, 550); ++i) { auto now = get(i); val[i].first = now.first; val[i].second = now.second; mx = max(mx, val[i].first + val[i].second); last_by_sum[val[i].first + val[i].second].insert(i); } for (int i = 0; i < min(n, 550); ++i) { if (val[i].first + val[i].second == mx) { is_worst[i] = true; know[i] = true; } if (val[i].first + val[i].second == 0) return i; } int l = 550; while (true) { auto now = get(l); last_by_sum[now.first + now.second].insert(l); val[l] = {now.first, now.second}; if (now.first + now.second == mx) break; ++l; } while (true) { int low = l, high = n-1; while (high != low) { int mid = (high + low + 1) >> 1; auto now = get(mid); int sum = now.first + now.second; if (sum == mx) { if (now.first == val[l].first) { low = mid+1; } else { high = mid-1; } continue; } if (now.first + now.second == 0) return mid; int v = mid; bool worth_left = true; while (sum < mx && worth_left) { --v; now = get(v); sum = now.first + now.second; set<int, greater<int>>& s = last_by_sum[sum]; auto it = s.upper_bound(v); if (it != s.end()) { if (val[v].first == val[*it].first) { worth_left = false; break; } } if (sum == 0) return v; } if (!worth_left) { int v = mid; while (sum < mx) { ++v; now = get(v); sum = now.first + now.second; if (sum == 0) return v; } l = v; continue; } if (now.first == val[l].first) { int v = mid; while (sum < mx) { ++v; now = get(v); sum = now.first + now.second; if (sum == 0) return v; } l = v; continue; } high = v-1; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...