結果

問題 No.3456 Common Difference is D
コンテスト
ユーザー あるふぁ
提出日時 2026-10-02 07:29:37
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 503 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,473 ms
コンパイル使用メモリ 186,260 KB
実行使用メモリ 22,600 KB
最終ジャッジ日時 2026-10-02 07:29:50
合計ジャッジ時間 10,473 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <map>
using namespace std;
using ll = long long;

int main(){
    int N, D;
    cin >> N >> D;
    vector<int> A(N);
    map<int, vector<int>> I;
    for (int i = 0; i < N; i++){
        cin >> A[i];
        I[A[i]].push_back(i);
    }

    ll ans = 0;
    for (int i = 0; i < N; i++){
        for (int j : I[A[i]+D]){
            ans += I[A[i]+2*D].end()-upper_bound(I[A[i]+2*D].begin(), I[A[i]+2*D].end(), j);
        }
    }

    cout << ans << endl;
}
0