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
def multiply(a, n):
if n == 2:
return a << 1
elif n == 3:
return a + (a << 1)
elif n == 4:
return a << 2
elif n == 5:
return a + (a << 2)
elif n == 6:
return (a << 1) + (a << 2)
elif n == 7:
return (a << 3) - a
elif n == 8:
return a << 3
elif n == 9:
return a + (a << 3)
elif n == 10:
return (a << 1) + (a << 3)
elif n == 11:
return a + (a << 1) + (a << 3)
elif n == 12:
return (a << 2) + (a << 3)
elif n == 13:
return a + (a << 2) + (a << 3)
elif n == 14:
return (a << 4) - (a << 1)
elif n == 15:
return (a << 4) - a
else:
return a * n
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):
n = j - k + 1
if n == 2:
ans = ans << 1
elif n == 3:
ans = ans + (ans << 1)
elif n == 4:
ans = ans << 2
elif n == 5:
ans = ans + (ans << 2)
elif n == 6:
ans = (ans << 1) + (ans << 2)
elif n == 7:
ans = (ans << 3) - ans
elif n == 8:
ans = ans << 3
elif n == 9:
ans = ans + (ans << 3)
elif n == 10:
ans = (ans << 1) + (ans << 3)
elif n == 11:
ans = ans + (ans << 1) + (ans << 3)
elif n == 12:
ans = (ans << 2) + (ans << 3)
elif n == 13:
ans = ans + (ans << 2) + (ans << 3)
elif n == 14:
ans = (ans << 4) - (ans << 1)
elif n == 15:
ans = (ans << 4) - ans
else:
ans *= n
if ans > 2000000000000000000:
ans = ans % 1000000009
else:
j += 1
print(ans % 1000000009)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
3080 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
3108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
3140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
3028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
3112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
3136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
3028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
3088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
3028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
3040 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
3288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
3284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
4180 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
155 ms |
8632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
922 ms |
30884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
686 ms |
76036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |