結果
| 問題 | No.3456 Common Difference is D |
| コンテスト | |
| ユーザー |
tau1235
|
| 提出日時 | 2026-02-28 15:49:46 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 127 ms / 2,000 ms |
| + 844µs | |
| コード長 | 492 bytes |
| 記録 | |
| コンパイル時間 | 2,142 ms |
| コンパイル使用メモリ | 340,808 KB |
| 実行使用メモリ | 14,724 KB |
| 最終ジャッジ日時 | 2026-07-25 06:38:15 |
| 合計ジャッジ時間 | 4,481 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
using ll=long long;
int n,d;
cin>>n>>d;
vector<int> a(n);
map<int,vector<int>> mp;
for (int i=0;i<n;i++){
cin>>a[i];
mp[a[i]].push_back(i);
}
auto f=[&](int x,int r){
if (!mp.count(x)) return 0LL;
ll ret=lower_bound(mp[x].begin(),mp[x].end(),r)-mp[x].begin();
return ret;
};
ll ans=0;
for (int i=0;i<n;i++){
ll c0=f(a[i]-d,i)-f(a[i]-d,0);
ll c1=f(a[i]+d,n)-f(a[i]+d,i+1);
ans+=c0*c1;
}
cout<<ans<<endl;
}
tau1235