이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "routers.h"
#define pb push_back
using namespace std;
std::vector<int> find_routers(int l, int n, int q) {
vector<int> ans = {0};
vector<int> firstSeen(n + 1, l);
vector<int> lastSeen(n + 1, 0);
vector<int> memo(l + 1, -1);
firstSeen[0] = 0;
lastSeen[0] = 1;
int lastRouterIndex = 0;
for (int toFind = 1; toFind <= n - 1; toFind++)
{
int lo = lastSeen[toFind - 1] + 1, hi = firstSeen[toFind + 1];
while(lo <= hi){
int mid = (lo + hi)/2;
int detected = (memo[mid] != -1 ? memo[mid] : use_detector(mid));
memo[mid] = detected;
if(detected >= toFind) hi = mid - 1;
else lo = mid + 1;
firstSeen[detected] = min(firstSeen[detected], mid);
lastSeen[detected] = max(lastSeen[detected], mid);
}
int nextRouter = lastRouterIndex + (lo - 1 - lastRouterIndex)*2;
ans.pb(nextRouter);
lastSeen[toFind] = max(lastSeen[toFind], nextRouter + 1);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |