結果
| 問題 | No.2821 A[i] ← 2A[j] - A[i] |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-07-29 16:46:07 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 942 bytes |
| 記録 | |
| コンパイル時間 | 276 ms |
| コンパイル使用メモリ | 73,392 KB |
| 実行使用メモリ | 9,280 KB |
| 最終ジャッジ日時 | 2026-07-05 08:54:53 |
| 合計ジャッジ時間 | 2,220 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 2 WA * 31 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 2821.cc: No.2821 A[i] 竊・2A[j] - A[i] - yukicoder
*/
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 300000;
const long long LINF = 1LL << 62;
/* typedef */
using ll = long long;
using sl = set<ll>;
/* global variables */
ll as[MAX_N], ds[MAX_N];
/* subroutines */
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%lld", as + i);
ll mind = LINF;
sl bs;
bs.insert(as[0]);
for (int i = 1; i < n; i++) {
auto [sit, f] = bs.insert(as[i]);
if (f) {
if (sit != bs.begin()) {
auto sit0 = sit; sit0--;
mind = min(mind, as[i] - *sit0);
}
auto sit1 = sit; sit1++;
if (sit1 != bs.end()) {
mind = min(mind, *sit1 - as[i]);
}
ds[i] = mind;
}
else
ds[i] = ds[i - 1];
}
for (int i = 0; i < n; i++) printf("%d\n", ds[i]);
return 0;
}
tnakao0123