제출 #883591

#제출 시각아이디문제언어결과실행 시간메모리
883591kongumFinding Routers (IOI20_routers)C++17
0 / 100
2054 ms604 KiB
#include <bits/stdc++.h> #include "routers.h" #define fi first #define se second #define all(a) (a).begin(), (a).end() using namespace std; using pii = pair<int, int>; using ti3 = tuple<int, int, int>; const int MAX = 100010; int arr[MAX], fir[MAX], cnt[MAX], res[MAX]; int lowerBound(int lo, int hi, int tar) { // tar + 1반환 while (lo + 1 < hi) { int mid = (lo + hi) / 2; int chk = use_detector(mid); if (chk < tar) lo = mid; else hi = mid; } return hi; } void divide(int lo, int hi) { int mid = (lo + hi) / 2; int tar = use_detector(mid); int lft = lowerBound(lo, hi, tar); int rgt = lowerBound(lo, hi, tar + 1) - 1; arr[lft] = tar; arr[rgt] = tar; if (lo + 1 < lft) divide(lo, lft - 1); if (mid < hi) divide(mid, hi); } std::vector<int> find_routers(int l, int n, int q) { for (int i = 0; i < MAX; i++) arr[i] = -1; divide(-1, l + 1); for (int i = 1; i < l; i++) arr[i] = max(arr[i], arr[i - 1]); for (int i = 0; i < l + 1; i++) { if (arr[i] >= 0) cnt[arr[i]]++; if (i >= 1 && arr[i] > arr[i - 1]) fir[arr[i]] = i; } fir[0] = 0; res[0] = 0; for (int i = 1; i < n; i++) { res[i] = res[i - 1] + (cnt[i - 1] - 1) * 2; cnt[i] -= cnt[i - 1] - 2; } vector<int> v; for (int i = 0; i < n; i++) v.push_back(res[i]); return v; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...