이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
#ifdef LOCAL
#include "/home/trcmai/code/tools.h"
#define debug(x...) \
cerr << "\e[91m" << __func__ << ":" << __LINE__ << " [" << #x << "] = ["; \
_print(x); \
cerr << "\e[39m" << endl;
#else
#define debug(x...)
#endif
using namespace std;
#define all(a) a.begin(), a.end()
#define ll long long
#define endl '\n'
const int N = 1e6 + 6, LOG = 27, MOD = 1e9 + 7;
const ll INF = 1e18;
ll a[N];
ll ask(int i)
{
if (a[i] != -1)
return a[i];
else
return a[i] = skim(i);
}
void solve(int N, int K, long long A, int S)
{
memset(a, -1, sizeof(a));
int l = 1, r = N - K + 1;
// Check xem ton tai doan lien tiep nao thoa man khong
while (l <= r) {
int m = (r + l) >> 1;
ll sum = 0;
for (int i = m; i <= m + K - 1; ++i) {
sum += ask(i);
}
if (sum >= A && sum <= 2 * A) {
vector<int> res;
for (int i = m; i <= m + K - 1; ++i)
res.emplace_back(i);
answer(res);
}
if (sum < A)
l = m + 1;
if (sum > 2 * A)
r = m - 1;
}
// Neu khong ton tai, check xem doan [1,k - 1] co ghep duoc voi vi tri ith thoa man khong
l = K, r = N - K + 1;
int pos = -1;
while (l <= r) {
int m = (r + l) >> 1;
ll val = ask(m);
if (val >= A) {
pos = m;
r = m - 1;
} else
l = m + 1;
}
if (pos != -1) {
vector<int> res;
ll sum = ask(pos);
for (int i = 1; i <= K - 1; ++i) {
sum += ask(i);
}
if (sum >= A && sum <= 2 * A) {
for (int i = 1; i <= K - 1; ++i)
res.emplace_back(i);
res.emplace_back(pos);
answer(res);
}
}
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... |