#include <bits/stdc++.h>
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2","popcnt")
using namespace std;
#ifdef MIKU
#define debug(x...) cout << '[' << #x << "] : ", dout(x)
void dout() { cout << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < k; i++)
typedef pair<int, int> pii;
const int MXN = 1000005, mod = 100000009;
int n, d, a[MXN];
int ADD(int a, int b) {
a += b;
a -= (a >= mod ? mod : 0);
return a;
}
int MUL(int a, int b) {
return a * b % mod;
}
struct SMG {
int val[MXN * 4], tag[MXN * 4];
void add_tag(int id, int t) {
val[id] = MUL(val[id], t);
tag[id] = MUL(tag[id], t);
}
void push(int id) {
if (tag[id] == 1) return;
add_tag(id * 2 + 1, tag[id]);
add_tag(id * 2 + 2, tag[id]);
tag[id] = 1;
}
void pull(int id) {
val[id] = ADD(val[id * 2 + 1], val[id * 2 + 2]);
}
void build(int id, int l, int r) {
val[id] = r - l;
tag[id] = 1;
if (l + 1 == r) return;
int mid = (l + r) >> 1;
build(id * 2 + 1, l, mid);
build(id * 2 + 2, mid, r);
}
void modify(int id, int l, int r, int _l, int _r, int v) {
if (_r <= l || r <= _l) return;
if (_l <= l && r <= _r) {
add_tag(id, v);
return;
}
int mid = (l + r) >> 1;
push(id);
modify(id * 2 + 1, l, mid, _l, _r, v);
modify(id * 2 + 2, mid, r, _l, _r, v);
pull(id);
}
int query(int id, int l, int r, int _l, int _r) {
if (_r <= l || r <= _l) return 0;
if (_l <= l && r <= _r) return val[id];
int mid = (l + r) >> 1;
push(id);
return ADD(query(id * 2 + 1, l, mid, _l, _r), query(id * 2 + 2, mid, r, _l, _r));
}
void DFS(int id, int l, int r) {
if (l + 1 == r) {
cout << val[id] << ' ';
return;
}
int mid = (l + r) >> 1;
DFS(id * 2 + 1, l, mid);
DFS(id * 2 + 2, mid, r);
}
} smg;
void miku() {
cin >> n >> d;
FOR(i, 0, n) cin >> a[i];
sort(a, a + n);
int p = 0;
smg.build(0, 0, n);
FOR(i, 1, n) {
while (a[p] + d < a[i]) p++;
smg.modify(0, 0, n, i, i + 1, smg.query(0, 0, n, p, i));
smg.modify(0, 0, n, 0, p, i - p + 1);
smg.modify(0, 0, n, p, i, i - p);
// smg.DFS(0, 0, n);
// cout << '\n';
}
cout << smg.val[0] << '\n';
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(iostream::failbit);
miku();
return 0;
}
Compilation message
tower.cpp: In function 'void miku()':
tower.cpp:19:38: warning: unused variable 'Z' [-Wunused-variable]
19 | #define FOR(i, j, k) for (int i = j, Z = k; i < k; i++)
| ^
tower.cpp:90:5: note: in expansion of macro 'FOR'
90 | FOR(i, 0, n) cin >> a[i];
| ^~~
tower.cpp:19:38: warning: unused variable 'Z' [-Wunused-variable]
19 | #define FOR(i, j, k) for (int i = j, Z = k; i < k; i++)
| ^
tower.cpp:94:5: note: in expansion of macro 'FOR'
94 | FOR(i, 1, n) {
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
6744 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
6612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
192 ms |
14952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
319 ms |
41812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |