# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
521394 | pavement | Hidden Sequence (info1cup18_hidden) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll pf[100005];
map<int, ll> mem;
ll qry(int x) {
if (mem.find(x) != mem.end()) return mem[x];
return mem[x] = skim(x);
}
void solve(int N, int K, ll A, int S) {
int lo = 1, hi = N, ans = -1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (qry(mid) >= A) ans = mid, hi = mid - 1;
else lo = mid + 1;
}
if (ans != -1 && ans < K) impossible();
if (ans != -1) {
ll cum = qry(ans);
vector<int> vec;
for (int i = 1; i < K; i++) cum += qry(i);
if (A <= cum && cum <= 2 * A) {
for (int i = 1; i < K; i++) vec.push_back(i);
vec.push_back(ans);
answer(vec);
return;
} else N = ans - 1;
}
ll cum = 0;
vector<int> vec;
for (int i = 1; i <= K; i++) pf[i] = pf[i - 1] + qry(i);
if (A <= pf[K] && pf[K] <= 2 * A) {
for (int i = 1; i <= K; i++) vec.push_back(i);
answer(vec);
return;
}
for (int i = N; i >= N - K + 1; i--) {
cum += qry(i);
vec.push_back(i);
if (A <= pf[K - (N - i + 1)] + cum && pf[K - (N - i + 1)] + cum <= 2 * A) {
for (int j = 1; j <= K - (N - i + 1); j++) vec.push_back(j);
answer(vec);
return;
}
}
impossible();
}