#P8962. 「WHOI-4」yadiw. Slua, gassp, lhtubs.
「WHOI-4」yadiw. Slua, gassp, lhtubs.
Background
If you know at least 3 of these things and you are not red — you are doing it wrong. Stop learning useless algorithms, go and solve some problems, learn how to use binary search.
Problem Description
Little F has a magical array . There are no duplicate elements in , and its length is . He sorted it using std::sort and believes it is ordered, so he is doing binary search in the following way. Obviously, whether it can be found only depends on the discretization result of the sequence, so you can directly treat as a permutation of .
int search(int key) {
int l = 1, r = n;
while (l <= r) {
int mid = (l + r) / 2;
if (a[mid] < key)
l = mid + 1;
else if (a[mid] == key)
return mid;
else
r = mid - 1;
}
return -1;
}
Unfortunately, in order to make him quit the “universal header” (wan neng tou), Little W wrote #define sort random_shuffle in bits/stdc++.h, which means that is actually a random permutation.
Now, for all in the range to , and for all in the range to , among all permutations of the array , how many of them can correctly find the -th smallest element (i.e., the return value is not )? Since the answer may be too large, output it modulo the given modulus .
Input Format
One line with two positive integers .
Output Format
Output lines. Line contains positive integers, representing, among elements, the number of permutations for which searching for can succeed.
998244353 5
1
1 2
4 4 4
12 12 14 18
48 54 60 66 72
Hint
Constraints
This problem uses Subtask judging.
- Subtask 1 ( pts): , ;
- Subtask 2 ( pts): , and is prime;
- Subtask 3 ( pts): , and is prime;
- Subtask 4 ( pts): .
For all testdata, , .
Translated by ChatGPT 5