結果
| 問題 |
No.1332 Range Nearest Query
|
| コンテスト | |
| ユーザー |
vwxyz
|
| 提出日時 | 2024-08-15 05:57:22 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,441 bytes |
| コンパイル時間 | 3,610 ms |
| コンパイル使用メモリ | 258,912 KB |
| 実行使用メモリ | 38,764 KB |
| 最終ジャッジ日時 | 2024-08-15 05:57:37 |
| 合計ジャッジ時間 | 14,097 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 WA * 33 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;
struct Query {
int value, left, right, index;
bool operator<(const Query& other) const {
return value < other.value;
}
};
int inf=1<<30;
int op(int a, int b) {
return max(a, b);
}
int e() {
return -inf; // effectively negative infinity
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> X(N);
for (int i = 0; i < N; ++i) {
cin >> X[i];
}
int Q;
cin >> Q;
vector<Query> query0, query1;
vector<int> ans(Q, inf);
for (int i = 0; i < N; ++i) {
query0.push_back({X[i], -1, -1, i});
query1.push_back({-X[i], -1, -1, i});
}
for (int i = 0; i < Q; ++i) {
int l, r, x;
cin >> l >> r >> x;
--l;
query0.push_back({x, l, r, i});
query1.push_back({-x, l, r, i});
}
sort(query0.begin(), query0.end());
sort(query1.begin(), query1.end());
for (auto& query : {query0, query1}) {
segtree<int, op, e> seg(N);
for (auto& q : query) {
if (q.left == -1) {
seg.set(q.index, q.value);
} else {
ans[q.index] = min(ans[q.index], q.value - seg.prod(q.left, q.right));
}
}
}
for (int i = 0; i < Q; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
vwxyz