이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* It's not that hard to come up with a almost-full solution. First, let non-lollipop
* be any prize with val < v. The number of non-lollipops is O(sqrt(n)), as there're
* at most 5 types of prizes, and #prize_val_v-1 < sqrt(#prize_val_v). (Technically,
* it should be O(sqrt(n) * log(log(n))), but log(log(n)) is quite small~)
*
* One can also notice that if two prizes u, v have the same value, then the sum of
* reponse for u and v is the same. Therefore, query any O(sqrt(n)) positions and we
* will find the number of non-lollipops. Finally, we know that lollipops account for
* most of the prizes, and their "left response" is increasing from left to right. We
* can treat (a[0]) from lollipops as an increasing sequence, and apply binary search
* to find all non-lollipops. Naturally, we will find the diamond.
*
* Doing O(sqrt(n)) separate binary searches require about 7000-9000 steps. In impl1,
* I optimize my search by applying those binary searches simultaneously. Namely, for
* each range [l,r] we're working with, query pos (l+r)/2 first. The monotonicity
* helps us determine the range of values for [l,(l+r)/2) and ((l+r)/2,r]. The
* approach is analogous to the well-known divide-and-conquer optimization. I know
* that this method has the same complexity, yet the constant, though I don't know,
* is smaller.
*
* Queries needed: sqrt(n) * log(n) (unsure about the const)
* Implementation 1
*/
#include <bits/stdc++.h>
#include "prize.h"
typedef std::vector<int> vec;
const int MAX_LOL = 711; // unproven value (?!)
int non_lol; // number of non-lollipops
int search(int l, int r, int val_lower, int val_upper) {
assert(val_lower <= val_upper);
if (l > r || val_lower == val_upper)
return -1;
int mid = (l + r) / 2, pt = mid, t = -1;
for (; l <= pt; pt--) {
vec res = ask(pt);
if (res[0] + res[1] == 0) // diamond found
return pt;
if (res[0] + res[1] == non_lol) {
t = res[0];
break;
}
}
return std::max(search(l, pt - 1, val_lower, t),
search(mid + 1, r, t + (mid - pt), val_upper));
}
int find_best(int n) {
non_lol = 0;
for (int _ = 0; _ <= MAX_LOL; _++) {
vec res = ask(rand() % n);
non_lol = std::max(non_lol, res[0] + res[1]);
}
return search(0, n - 1, 0, MAX_LOL);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |