N, D = map(int, input().split())
blocks = sorted(list(map(int, input().split())))
def binary_search_i(l, r, size, list):
ans = r + 1
while r >= l:
m = (l + r) // 2
# m = l + floor(log10(r - l + 1))
# m = l + (r - l) // 1000000
if size <= list[m] + D:
r = m - 1
ans = m
else:
l = m + 1
return ans
def binary_search_j(l, r, size, list):
ans = r + 1
while r >= l:
m = (l + r) // 2
if list[m] > size + D:
r = m - 1
ans = m
else:
l = m + 1
return ans
ans = 1
i = 0
j = 1
while j < N:
prev_j = j
# while i < j and blocks[j] > blocks[i] + D:
# i += 1
i = binary_search_i(i, j - 1, blocks[j], blocks)
if i < j:
j = binary_search_j(prev_j, N - 1, blocks[i], blocks)
for k in range(prev_j, j):
if (k - i + 1) == 2:
ans = ans << 1
elif (k - i + 1) == 4:
ans = ans << 2
elif (k - i + 1) == 8:
ans = ans << 3
else:
ans *= (k - i + 1)
if ans > 2000000000000000000:
ans = ans % 1000000009
else:
j += 1
print(ans % 1000000009)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
3056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
3064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
4112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
8440 KB |
Output is correct |
2 |
Correct |
76 ms |
8484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
881 ms |
30712 KB |
Output is correct |
2 |
Correct |
253 ms |
30884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
581 ms |
75824 KB |
Output is correct |
2 |
Execution timed out |
1077 ms |
75848 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |