結果
| 問題 | No.3456 Common Difference is D |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-02 16:49:06 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 253 ms / 2,000 ms |
| + 394µs | |
| コード長 | 555 bytes |
| 記録 | |
| コンパイル時間 | 3,231 ms |
| コンパイル使用メモリ | 186,904 KB |
| 実行使用メモリ | 30,336 KB |
| 最終ジャッジ日時 | 2026-10-02 16:49:14 |
| 合計ジャッジ時間 | 7,368 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#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++){
ll l = lower_bound(I[A[i]-D].begin(), I[A[i]-D].end(), i)-I[A[i]-D].begin();
ll r = I[A[i]+D].end()-upper_bound(I[A[i]+D].begin(), I[A[i]+D].end(), i);
ans += l*r;
}
cout << ans << endl;
}