結果
問題 | No.1332 Range Nearest Query |
ユーザー | SSRS |
提出日時 | 2021-01-08 23:12:31 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,728 bytes |
コンパイル時間 | 2,309 ms |
コンパイル使用メモリ | 185,552 KB |
実行使用メモリ | 59,836 KB |
最終ジャッジ日時 | 2024-11-16 16:28:12 |
合計ジャッジ時間 | 117,949 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,496 KB |
testcase_01 | AC | 2 ms
45,972 KB |
testcase_02 | AC | 2 ms
10,496 KB |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | AC | 1,572 ms
48,724 KB |
testcase_27 | AC | 1,588 ms
48,596 KB |
testcase_28 | AC | 163 ms
13,976 KB |
testcase_29 | AC | 173 ms
13,976 KB |
testcase_30 | AC | 187 ms
14,628 KB |
testcase_31 | AC | 117 ms
13,592 KB |
testcase_32 | AC | 183 ms
14,376 KB |
testcase_33 | AC | 191 ms
14,624 KB |
testcase_34 | AC | 145 ms
14,104 KB |
testcase_35 | AC | 166 ms
14,196 KB |
testcase_36 | AC | 160 ms
8,216 KB |
testcase_37 | AC | 178 ms
8,652 KB |
testcase_38 | TLE | - |
testcase_39 | AC | 1,125 ms
11,512 KB |
testcase_40 | TLE | - |
testcase_41 | AC | 1,970 ms
16,384 KB |
testcase_42 | TLE | - |
testcase_43 | TLE | - |
testcase_44 | TLE | - |
testcase_45 | TLE | - |
testcase_46 | TLE | - |
testcase_47 | TLE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; template <typename T> struct binary_indexed_tree{ int N; vector<T> BIT; binary_indexed_tree(int n){ N = 1; while (N < n){ N *= 2; } BIT = vector<T>(N + 1, 0); } void add(int i, T x){ i++; while (i <= N){ BIT[i] += x; i += i & -i; } } T sum(int i){ T ans = 0; while (i > 0){ ans += BIT[i]; i -= i & -i; } return ans; } T sum(int L, int R){ return sum(R) - sum(L); } T all(){ return BIT[N]; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int> X(N); for (int i = 0; i < N; i++){ cin >> X[i]; } vector<int> X2 = X; sort(X2.begin(), X2.end()); int Q; cin >> Q; vector<int> l(Q), r(Q), x(Q); for (int i = 0; i < Q; i++){ cin >> l[i] >> r[i] >> x[i]; l[i]--; } vector<int> tv(Q, INF), fv(Q, -1); int C = 0; while (true){ C++; assert(C <= 31); vector<int> mid(Q, -1); bool update = false; for (int i = 0; i < Q; i++){ if (tv[i] - fv[i] > 1){ mid[i] = (tv[i] + fv[i] + 2) / 2 - 1; update = true; } } if (!update){ break; } vector<vector<int>> padd(N); for (int i = 0; i < N; i++){ int p = lower_bound(X2.begin(), X2.end(), X[i]) - X2.begin(); padd[i].push_back(p); } vector<vector<tuple<int, int, int>>> add(N); vector<vector<tuple<int, int, int>>> sub(N); for (int i = 0; i < Q; i++){ if (mid[i] != -1){ int L = x[i] - mid[i]; int R = x[i] + mid[i]; int Lp = lower_bound(X2.begin(), X2.end(), L) - X2.begin(); int Rp = upper_bound(X2.begin(), X2.end(), R) - X2.begin(); if (l[i] > 0){ sub[l[i] - 1].push_back(make_tuple(Lp, Rp, i)); } add[r[i] - 1].push_back(make_tuple(Lp, Rp, i)); } } binary_indexed_tree<int> BIT(N); vector<int> cnt(Q, 0); for (int i = 0; i < N; i++){ for (int j : padd[i]){ BIT.add(j, 1); } int addcnt = add[i].size(); for (int j = 0; j < addcnt; j++){ int L = get<0>(add[i][j]); int R = get<1>(add[i][j]); int id = get<2>(add[i][j]); cnt[id] += BIT.sum(L, R); } int subcnt = sub[i].size(); for (int j = 0; j < subcnt; j++){ int L = get<0>(sub[i][j]); int R = get<1>(sub[i][j]); int id = get<2>(sub[i][j]); cnt[id] -= BIT.sum(L, R); } } for (int i = 0; i < Q; i++){ if (mid[i] != -1){ if (cnt[i] == 0){ fv[i] = mid[i]; } else { tv[i] = mid[i]; } } } } for (int i = 0; i < Q; i++){ cout << tv[i] << "\n"; } }