結果
問題 | No.1332 Range Nearest Query |
ユーザー | hir355 |
提出日時 | 2021-01-08 23:07:57 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,302 bytes |
コンパイル時間 | 2,556 ms |
コンパイル使用メモリ | 190,140 KB |
実行使用メモリ | 16,632 KB |
最終ジャッジ日時 | 2024-04-28 04:56:53 |
合計ジャッジ時間 | 23,910 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 465 ms
11,984 KB |
testcase_04 | WA | - |
testcase_05 | AC | 470 ms
11,980 KB |
testcase_06 | AC | 406 ms
16,500 KB |
testcase_07 | AC | 415 ms
16,508 KB |
testcase_08 | AC | 410 ms
16,492 KB |
testcase_09 | AC | 412 ms
16,452 KB |
testcase_10 | AC | 409 ms
16,440 KB |
testcase_11 | AC | 411 ms
16,504 KB |
testcase_12 | AC | 414 ms
16,504 KB |
testcase_13 | AC | 412 ms
16,488 KB |
testcase_14 | AC | 414 ms
16,468 KB |
testcase_15 | AC | 418 ms
16,608 KB |
testcase_16 | AC | 510 ms
16,444 KB |
testcase_17 | AC | 504 ms
16,496 KB |
testcase_18 | AC | 516 ms
16,496 KB |
testcase_19 | AC | 493 ms
16,532 KB |
testcase_20 | AC | 502 ms
16,500 KB |
testcase_21 | WA | - |
testcase_22 | AC | 508 ms
16,504 KB |
testcase_23 | AC | 503 ms
16,492 KB |
testcase_24 | AC | 501 ms
16,500 KB |
testcase_25 | WA | - |
testcase_26 | AC | 410 ms
16,452 KB |
testcase_27 | AC | 364 ms
16,632 KB |
testcase_28 | AC | 207 ms
5,376 KB |
testcase_29 | AC | 207 ms
5,376 KB |
testcase_30 | AC | 206 ms
5,376 KB |
testcase_31 | AC | 199 ms
5,376 KB |
testcase_32 | AC | 204 ms
5,376 KB |
testcase_33 | AC | 205 ms
5,376 KB |
testcase_34 | AC | 204 ms
5,376 KB |
testcase_35 | AC | 202 ms
5,376 KB |
testcase_36 | AC | 202 ms
5,376 KB |
testcase_37 | AC | 208 ms
5,376 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 500 ms
16,332 KB |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | AC | 395 ms
10,932 KB |
ソースコード
#include <atcoder/segtree> #include <bits/stdc++.h> using namespace std; using namespace atcoder; #define INF_LL 100000000000000000LL #define INF 2000000000 #define MOD 1000000007 #define ll long long #define all(x) x.begin(), x.end() #define REP(i, a, b) for(int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) // typedef float double; // typedef priority_queue prique; typedef pair<ll, ll> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<P> vp; typedef vector<ll> vl; typedef vector<vi> matrix; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int sign[2] = {1, -1}; template <class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } ll modpow(ll a, ll b, ll m) { if(b == 0) return 1; ll t = modpow(a, b / 2, m); if(b & 1) { return (t * t % m) * a % m; } else { return t * t % m; } } struct edge { int to; ll cost; edge(int t, ll c) { to = t, cost = c; } }; typedef vector<vector<edge>> graph; // using mint = modint998244353; int minop(int x, int y) {return min(x, y);} int maxop(int x, int y) {return max(x, y);} int mine() {return INF;} int maxe() {return -INF;} int main() { int n, q; cin >> n; vector<pair<int, int>> a(n); rep(i, n) {cin >> a[i].first;a[i].second = i;} segtree<int, maxop, maxe> seg1(n); segtree<int, minop, mine> seg2(n); rep(i, n) seg2.set(i, a[i].first); sort(all(a)); cin >> q; vector<tuple<int, int, int, int>> query(q); rep(i, q){ int l, r, x; cin >> l >> r >> x; query[i] = {x, l, r, i}; } sort(all(query)); int idx = 0; rep(i, q){ int x, l, r, g; tie(x, l, r, g) = query[i]; while(idx < n && x > a[idx].first){ seg1.set(a[idx].second, seg2.get(a[idx].second)); seg2.set(a[idx].second, mine()); idx++; } get<0>(query[i]) = min(seg2.prod(l - 1, r) - x, x - seg1.prod(l - 1, r)); } sort(begin(query), end(query), [](const auto &x, const auto &y){return get<3>(x) < get<3>(y);}); rep(i, q){ cout << get<0>(query[i]) << endl; } return 0; }