提出 #73071899


ソースコード 拡げる

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define fastio cin.tie(0)->sync_with_stdio(0)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;

int main() {
    fastio; int N, D; cin >> N >> D;
    vector<int> v(N);
    for (auto& i : v) cin >> i;
    ll ans = 0;
    int L = 0;
    set<int> s;
    for (int R = 0; R < N; R++) {
        while (1) {
            auto it = s.lower_bound(v[R]);
            bool chk = false;
            if (it != s.end() && *it < v[R]+D) chk = true;
            if (it != s.begin() && *prev(it) > v[R]-D) chk = true;
            if (!chk) break;
            s.erase(v[L]); L++;
        }
        s.insert(v[R]);
        ans += R-L+1;
    }
    cout << ans << "\n";
    return 0;
}

提出情報

提出日時
問題 E - Sparse Range
ユーザ Lov34ever
言語 C++23 (GCC 15.2.0)
得点 450
コード長 938 Byte
結果 AC
実行時間 520 ms
メモリ 23644 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 3
AC × 21
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
min1.txt AC 2 ms 3440 KiB
min2.txt AC 2 ms 3656 KiB
random_01.txt AC 204 ms 9668 KiB
random_02.txt AC 186 ms 8608 KiB
random_03.txt AC 195 ms 8896 KiB
random_04.txt AC 162 ms 8260 KiB
random_05.txt AC 118 ms 4940 KiB
random_06.txt AC 67 ms 4288 KiB
random_07.txt AC 103 ms 5056 KiB
random_08.txt AC 76 ms 4624 KiB
random_09.txt AC 103 ms 5032 KiB
random_10.txt AC 68 ms 4496 KiB
random_11.txt AC 155 ms 8540 KiB
random_12.txt AC 8 ms 3788 KiB
random_13.txt AC 27 ms 5056 KiB
random_14.txt AC 333 ms 23636 KiB
random_15.txt AC 520 ms 23624 KiB
random_16.txt AC 329 ms 23644 KiB
sample_01.txt AC 2 ms 3552 KiB
sample_02.txt AC 1 ms 3552 KiB
sample_03.txt AC 1 ms 3556 KiB