結果
問題 | No.1332 Range Nearest Query |
ユーザー | SSRS |
提出日時 | 2021-01-08 23:11:56 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,685 bytes |
コンパイル時間 | 2,019 ms |
コンパイル使用メモリ | 185,404 KB |
実行使用メモリ | 94,136 KB |
最終ジャッジ日時 | 2024-11-16 16:17:38 |
合計ジャッジ時間 | 113,573 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,496 KB |
testcase_01 | AC | 2 ms
45,844 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,502 ms
48,472 KB |
testcase_27 | AC | 1,543 ms
88,280 KB |
testcase_28 | AC | 159 ms
13,724 KB |
testcase_29 | AC | 170 ms
45,140 KB |
testcase_30 | AC | 178 ms
14,496 KB |
testcase_31 | AC | 115 ms
41,940 KB |
testcase_32 | AC | 175 ms
13,992 KB |
testcase_33 | AC | 179 ms
9,124 KB |
testcase_34 | AC | 141 ms
8,600 KB |
testcase_35 | AC | 161 ms
8,680 KB |
testcase_36 | AC | 153 ms
8,344 KB |
testcase_37 | AC | 173 ms
8,656 KB |
testcase_38 | TLE | - |
testcase_39 | AC | 1,055 ms
11,416 KB |
testcase_40 | TLE | - |
testcase_41 | AC | 1,910 ms
16,384 KB |
testcase_42 | TLE | - |
testcase_43 | AC | 2,478 ms
20,864 KB |
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); while (true){ 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"; } }