結果

問題 No.1110 好きな歌
ユーザー Drice
提出日時 2020-07-10 22:30:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 553 bytes
コンパイル時間 482 ms
コンパイル使用メモリ 45,312 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-11 09:49:37
合計ジャッジ時間 4,826 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<algorithm>
struct Element{
    int v; int id;
    bool operator < (const Element &other)const{
        return v<other.v;
    }
};
Element a[200005];
int ans[200005];

int main(){
    int n,d;
    scanf("%d%d",&n,&d);
    for(int i = 1; i <= n; i++){
        scanf("%d",&a[i].v);
        a[i].id = i;
    }
    std::sort(a+1,a+1+n);
    int p = n;
    for(int i = n; i >= 1; i--){
        while(p>=1 && a[p].v>a[i].v-d) p--;
        ans[a[i].id] = p;
    }
    for(int i = 1; i <= n; i++) printf("%d\n",ans[i]);
    return 0;
}
0