이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <map>
#include "books.h"
using namespace std;
map<int, long long> m;
long long get(int x, int K) {
long long ret = 0;
for (int i = 0; i < K; i++) {
if (m.find(x + i + 1) == m.end()) m[x + i + 1] = skim(x + i + 1);
ret += m[x + i + 1];
}
return ret;
}
void solve(int N, int K, long long A, int S) {
int l = 0, r = N - K + 1;
while (l <= r) {
int m = (l + r) / 2;
if (get(m, 1) > 2 * A / K) r = m - 1;
else if (get(m + K - 1, 1) < (A + K - 1) / K) l = m + 1;
else {
int lt = 0, rt = K - 1;
long long t = 0;
while (lt <= rt) {
if (get(m, lt + 1) + get(m + lt, 1) * (K - lt - 1) > 2 * A) {
r = m - 1;
goto next;
}
if (get(m + rt, K - rt) + get(m + rt, 1) * rt < A) {
l = m + 1;
goto next;
}
lt++, rt--;
}
t = get(m, K);
if (t < A) l = m + 1;
else if (t > 2 * A) r = m - 1;
else {
vector<int> v;
for (int i = 0; i < K; i++) v.push_back(m + i + 1);
answer(v);
return;
}
next:;
}
}
if (get(0, K) > 2 * A) {
impossible();
return;
} else if (get(0, K) >= A) {
vector<int> v;
for (int i = 0; i < K; i++) v.push_back(i + 1);
answer(v);
return;
}
l = K + 1, r = N - 1;
while (l <= r) {
int m = (l + r) / 2;
long long t = get(0, K - 1) + get(m, 1);
if (t < A) l = m + 1;
else if (t > 2 * A) r = m - 1;
else {
vector<int> v;
for (int i = 0; i < K - 1; i++) v.push_back(i + 1);
v.push_back(m + 1);
answer(v);
return;
}
}
impossible();
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |