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 <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
read the sol a long time ago and remember some ideas from there
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "books.h"
void solve(int n, int k, long long A, int S) {
map<ll,ll> mp;
auto my_skim = [&](ll i){
if(mp.count(i)) return mp[i];
else return mp[i] = skim(i);
};
ll first_big = n+1;
ll l = 1, r = n;
while(l <= r){
ll mid = (l+r) >> 1;
ll val = my_skim(mid);
if(val >= A){
first_big = mid;
r = mid-1;
}
else{
l = mid+1;
}
}
vector<ll> a(k+5);
rep1(i,k){
a[i] = my_skim(i);
}
if(first_big <= n){
ll sum = my_skim(first_big);
rep1(i,k-1) sum += a[i];
if(sum >= A and sum <= 2*A){
vector<int> ans;
rep1(i,k-1) ans.pb(i);
ans.pb(first_big);
answer(ans);
return;
}
}
ll sum = 0;
rep1(i,k) sum += a[i];
if(sum > 2*A){
impossible();
return;
}
deque<int> dq;
rep1(i,k) dq.pb(i);
if(sum >= A){
vector<int> ans(all(dq));
answer(ans);
return;
}
ll ptr = first_big-1;
rev(i,k,1){
sum -= a[i];
sum += my_skim(ptr);
dq.pop_back();
dq.push_front(ptr);
ptr--;
if(sum >= A){
assert(sum <= 2*A);
vector<int> ans(all(dq));
answer(ans);
return;
}
}
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... |