제출 #882355

#제출 시각아이디문제언어결과실행 시간메모리
882355pirhosigFinding Routers (IOI20_routers)C++17
100 / 100
2 ms856 KiB
#include "routers.h" #include <bits/stdc++.h> using namespace std; int cqu(unordered_map<int, int>& cac, int val) { if (cac.find(val) == cac.end()) cac[val] = use_detector(val); return cac.at(val); } int solve(unordered_map<int, int>& cac, int low, int upp, int val) { while (low < upp) { int mid = (low + upp + 1) / 2; int qres = cqu(cac, mid); // cerr << mid << endl; if (qres >= val) upp = mid - 1; else low = mid; } return low; } vector<int> find_routers(int l, int n, int q) { vector<int> ans; ans.push_back(0); unordered_map<int, int> cac; if (n == 2) { int res = solve(cac, 0, l, 1); ans.push_back(res * 2); return ans; } vector<pair<int, int>> close; close.push_back({0, 0}); constexpr int jump = 60; for (int i = jump; i < l; i += jump) close.push_back({cqu(cac, i), i}); close.push_back({cqu(cac, l), l}); for (int i = 1; i < n; ++i) { auto upp = lower_bound(close.begin(), close.end(), make_pair(i, 0)); auto low = prev(upp); int res = solve(cac, low->second, upp->second, i); ans.push_back(2 * res - ans.back()); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...