이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5+10;
const int X = 12;
ll n, k, a, s;
bool us[N];
ll val[N];
ll ask(int x) {
if (us[x]) return val[x];
us[x]=true;
return val[x]=skim(x);
}
bool check(vector<int> v) {
ll sm=0;
for (auto u : v) sm+=ask(u);
return a <= sm && sm <= 2*a;
}
void solve(int _n, int _k, ll _a, int _s) {
n=_n, k=_k, a=_a, s=_s;
ll sm=0;
vector<int> v;
for (int i=1; i<k; ++i) v.push_back(i), sm+=ask(i);
if (sm+ask(k) > 2*a) {
impossible();
return;
} else if (a <= sm+ask(k) && sm+ask(k) <= 2*a) {
v.push_back(k);
answer(v);
return;
} sm+=ask(k);
int l=k, r=n, res=l;
while (l <= r) {
int m=(l+r)/2;
if (ask(m) <= a) res=m, l=m+1;
else r=m-1;
}
set<int> sx;
for (int i=1; i<=k; ++i) sx.insert(i);
if (res+1 <= n && sm-ask(k)+ask(res+1) <= 2*a && sm-ask(k)+ask(res+1) >= a) {
sx.erase(k), sx.insert(res+1);
answer(vector<int>(sx.begin(), sx.end()));
return;
}
int lp=k, rp=res;
while (sm < a && lp > 0) {
if (sm-ask(lp)+ask(rp) <= 2*a) {
sm=sm-ask(lp)+ask(rp);
sx.erase(lp), sx.insert(rp);
--lp, --rp;
} else {
int lf=lp, rf=rp, res=lp;
while (lf <= rf) {
int m=(lf+rf)/2;
if (sm-ask(lp)+ask(m) <= 2*a) res=m, lf=m+1;
else rf=m-1;
}
sx.erase(lp), sx.insert(res);
sm=sm-ask(lp)+ask(res);
assert(a <= sm && sm <= 2*a);
vector<int> v(sx.begin(), sx.end());
answer(v);
}
}
if (sm >= a && sm <= 2*a) answer(vector<int>{sx.begin(), sx.end()});
else 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... |