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>
#define int long long
using namespace std;
int cache[100005];
int n;
int query(int a){
assert(a>=1 && a<=n);
if (cache[a]!=-1) return cache[a];
return cache[a] = skim(a);
}
int find_val(int a, int b, int c = 1, int d = n){
if (query(c)>b) return -(c-1);
if (query(c)>=a) return c;
if (query(d)<a) return -d;
if (query(d)<=b) return d;
while (c+1<d){
int mid = (c+d)/2;
int t = query(mid);
if (a<=t && t<=b) return mid;
if (t<a) c = mid;
else d = mid;
}
return -c;
}
void check_ans(vector<int32_t> t){
int sum = 0;
sort(t.begin(),t.end());
for (int x = 1; x<t.size(); x++){
assert(t[x-1]!=t[x]);
}
}
void solve(int32_t N, int32_t K, long long A, int32_t S) {
memset(cache,-1,sizeof(cache));
n = N;
int en = N;
vector<int32_t> extr;
for (int x = K-1; x>=0; x--){
vector<int32_t> ans;
for (int y = 0; y<x; y++){
ans.push_back(y+1);
}
for (auto y : extr) ans.push_back(y);
int sum = 0;
for (auto x : ans){
sum += query(x);
}
int res = find_val(A-sum,2*A-sum,x+1,en);
if (res>0){
ans.push_back(res);
check_ans(ans);
answer(ans);
return;
}
en = -res-1;
if (x>en){
impossible();
return;
}
extr.push_back(-res);
}
impossible();
}
Compilation message (stderr)
books.cpp: In function 'void check_ans(std::vector<int>)':
books.cpp:32:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int x = 1; x<t.size(); x++){
| ~^~~~~~~~~
books.cpp:30:9: warning: unused variable 'sum' [-Wunused-variable]
30 | int sum = 0;
| ^~~
# | 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... |