제출 #411525

#제출 시각아이디문제언어결과실행 시간메모리
411525Aldas25A Difficult(y) Choice (BOI21_books)C++14
0 / 100
40 ms308 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define f first #define s second #define pb push_back typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vii; typedef vector<ll> vl; const int MAXN = 1e5 + 100; int n, k, s; ll a; unordered_map<int, ll> saved; ll get (int i) { if (saved[i] > 0)return saved[i]; saved[i] = skim(i); return saved[i]; } ll getS (int i) { ll sum = 0; FOR(j, i, i+k-1) sum += get(j); return sum; } void ans (int i) { vi ret; FOR(j, i, i+k-1) ret.pb(j); answer(ret); } void ans2 (int i) { vi ret; FOR(j, i, i+k-2) ret.pb(j); ret.pb(i+k); answer(ret); } set<ll> cont; map<ll, int> to; void ansCont () { vi ret; for (auto p : cont) ret.pb(to[p]); answer(ret); } void solve(int N, int K, long long A, int S) { n = N; k = K; a = A; s = S; if (s == n) { //FOR(i, 1, n) get(i); FOR(i, 1, n) FOR(j, i+k-1, n) { /// [i; i + k/2-1] ir [j - k/2+1; j] ll s = 0; FOR(xx, i, i+k/2-1) s += get(xx); FOR(xx, j - (k+1)/2 + 1, j) s += get(xx); if (a <= s && s <= 2*a) { vi ret; FOR(xx, i, i+k/2-1) ret.pb(xx); FOR(xx, j - (k+1)/2 + 1, j) ret.pb(xx); answer(ret); return; } } impossible(); return; } int le = 1, ri = n-k+1; while (le < ri) { int mid = (le+ri+1)/2; ll s = getS(mid); if (a <= s && s <= 2*a) { ans(mid); return; } if (s > 2*a) ri = mid-1; else le = mid; } ll s = getS(le); ll altS = 0; if (le + k <= n) altS = s - get(le+k-1) + get(le+k); if (a <= s && s <= 2*a) ans(le); else if (a <= altS && altS <= 2*a) ans2(le); else if (altS > 2*a) { /// blogai altS += get(le+k-1); FOR(j, le, le+k-1) { ll curS = altS - get(j); if (a <= curS && curS <= 2*a) { vi ret; FOR(xx, le, le+k-1) { if (xx == j) continue; ret.pb(xx); } ret.pb(le+k); answer(ret); return; } } } else impossible(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...