Submission #73081021
Source Code Expand
#include <stdio.h>
#include <set>
#include <algorithm>
constexpr int N = 400005;
int a[N];
int main() {
int n, d;
scanf("%d%d", &n, &d);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
std::multiset<int> st;
auto check = [&] (auto it) {
if (it != st.begin() && *it - *std::prev(it) < d) return false;
if (std::next(it) != st.end() && *std::next(it) - *it < d) return false;
return true;
};
long long ans = 0;
for (int l = 1, r = 1; r <= n; r++) {
auto it = st.insert(a[r]);
while (!check(it)) st.erase(st.find(a[l++]));
ans += r - l + 1;
}
printf("%lld\n", ans);
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Sparse Range |
| User | CyrilZsy |
| Language | C++23 (GCC 15.2.0) |
| Score | 450 |
| Code Size | 699 Byte |
| Status | AC |
| Exec Time | 440 ms |
| Memory | 24140 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 450 / 450 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | min1.txt, min2.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| min1.txt | AC | 1 ms | 3748 KiB |
| min2.txt | AC | 1 ms | 3828 KiB |
| random_01.txt | AC | 161 ms | 9964 KiB |
| random_02.txt | AC | 151 ms | 9164 KiB |
| random_03.txt | AC | 152 ms | 9260 KiB |
| random_04.txt | AC | 127 ms | 8648 KiB |
| random_05.txt | AC | 87 ms | 5448 KiB |
| random_06.txt | AC | 50 ms | 4940 KiB |
| random_07.txt | AC | 80 ms | 5356 KiB |
| random_08.txt | AC | 59 ms | 4924 KiB |
| random_09.txt | AC | 80 ms | 5320 KiB |
| random_10.txt | AC | 54 ms | 4844 KiB |
| random_11.txt | AC | 122 ms | 9032 KiB |
| random_12.txt | AC | 9 ms | 4172 KiB |
| random_13.txt | AC | 35 ms | 5228 KiB |
| random_14.txt | AC | 257 ms | 24136 KiB |
| random_15.txt | AC | 440 ms | 24140 KiB |
| random_16.txt | AC | 255 ms | 24124 KiB |
| sample_01.txt | AC | 1 ms | 3916 KiB |
| sample_02.txt | AC | 1 ms | 3724 KiB |
| sample_03.txt | AC | 1 ms | 3748 KiB |