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 <bits/stdc++.h>
#include "books.h"
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define RF(n) RFi(i,n)
#define RFi(i,n) RFl(i,0,n)
#define RFl(i,l,n) for(int i=n-1;i>=l;i--)
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define mem(v,x) memset(v,x,sizeof v)
#define ff first
#define ss second
#define RAN(a,b) uniform_int_distribution<int> (a, b)(rng)
#define debug(x) (cerr << (#x) << " = " << x << "\n")
#define cmax(a,b) (a = max(a,b))
#define cmin(a,b) (a = min(a,b))
using namespace std;
//
// --- Sample implementation for the task books ---
//
// To compile this program with the sample grader, place:
// books.h books_sample.cpp sample_grader.cpp
// in a single folder and run:
// g++ books_sample.cpp sample_grader.cpp
// in this folder.
//
// N: number of books, K: final set size, A: target sum is from A to 2*A, S: query time
// long long skim(int a) : returns x_a;
// void impossible();
// void answer(vector<int> v);
long long arr[100010];
int SSSS, NNNN;
int skimcnt;
set<int> searched;
long long aux(int i){
if(arr[i]) return arr[i];
searched.insert(i);
arr[i] = skim(i);
skimcnt++;
return arr[i];
}
void reset(){
skimcnt = 0;
SSSS = 0;
NNNN = 0;
for(int i : searched){
arr[i] = 0;
}
searched.clear();
}
void solve(int N, int K, long long A, int S) {
SSSS = S;
NNNN = N;
F(K-1) aux(i+1);
int boundL = 0, boundR = N + 1;
while(boundL + 1 != boundR){
int mid = (boundL + boundR) >> 1;
if(aux(mid) >= A){
boundR = mid;
}else{
boundL = mid;
}
}
if(boundR < K) {reset(); impossible();}
if(boundR <= N){
long long temp1 = aux(boundR);
F(K-1) temp1 += aux(i+1);
if(temp1 >= A && temp1 <= 2*A){
vector<int> v;
v.pb(boundR);
F(K-1) v.pb(i+1);
reset();
answer(v);
}
}
long long mx = 0;
F(K) mx += aux(boundL - i);
long long mn = 0;
F(K) mn += aux(i+1);
if(mn > 2*A || mx < A) {reset(); impossible();}
F(K+1){
long long curr = 0;
vector<int> v;
Fi(j, i) curr += aux(j+1), v.pb(j+1);
Fi(j, K-i) curr += aux(boundL - j), v.pb(boundL-j);
if( 2*A >= curr && curr >= A) {reset(); answer(v);}
}
}
# | 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... |