結果
問題 | No.1332 Range Nearest Query |
ユーザー | penguinman |
提出日時 | 2020-11-23 04:15:44 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,815 bytes |
コンパイル時間 | 1,998 ms |
コンパイル使用メモリ | 179,968 KB |
実行使用メモリ | 22,008 KB |
最終ジャッジ日時 | 2023-09-30 23:17:22 |
合計ジャッジ時間 | 15,344 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,384 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 294 ms
16,192 KB |
testcase_04 | WA | - |
testcase_05 | AC | 289 ms
15,948 KB |
testcase_06 | AC | 230 ms
20,348 KB |
testcase_07 | AC | 225 ms
20,120 KB |
testcase_08 | AC | 221 ms
21,272 KB |
testcase_09 | AC | 221 ms
20,544 KB |
testcase_10 | AC | 219 ms
20,184 KB |
testcase_11 | AC | 226 ms
21,924 KB |
testcase_12 | AC | 218 ms
20,044 KB |
testcase_13 | AC | 224 ms
20,828 KB |
testcase_14 | AC | 222 ms
20,548 KB |
testcase_15 | AC | 222 ms
20,464 KB |
testcase_16 | AC | 325 ms
20,408 KB |
testcase_17 | AC | 318 ms
20,024 KB |
testcase_18 | AC | 310 ms
20,128 KB |
testcase_19 | AC | 296 ms
20,816 KB |
testcase_20 | AC | 305 ms
21,544 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 302 ms
20,148 KB |
testcase_25 | AC | 305 ms
20,292 KB |
testcase_26 | AC | 173 ms
20,584 KB |
testcase_27 | AC | 148 ms
20,632 KB |
testcase_28 | AC | 49 ms
6,948 KB |
testcase_29 | AC | 52 ms
6,872 KB |
testcase_30 | AC | 53 ms
6,980 KB |
testcase_31 | AC | 44 ms
6,876 KB |
testcase_32 | AC | 60 ms
6,864 KB |
testcase_33 | AC | 62 ms
6,976 KB |
testcase_34 | AC | 45 ms
6,972 KB |
testcase_35 | AC | 48 ms
6,988 KB |
testcase_36 | AC | 48 ms
7,068 KB |
testcase_37 | AC | 52 ms
7,028 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 319 ms
21,176 KB |
testcase_41 | WA | - |
testcase_42 | AC | 212 ms
13,284 KB |
testcase_43 | WA | - |
testcase_44 | AC | 263 ms
15,328 KB |
testcase_45 | WA | - |
testcase_46 | AC | 211 ms
11,180 KB |
testcase_47 | WA | - |
ソースコード
#include<bits/stdc++.h> using std::cin; using std::cout; using std::vector; using ll=long long; #define int long long #define endl "\n"; const int inf=1<<30; //セグ木 struct Segtree{ int N; vector<int> node; Segtree(int n){ N=1; while(N<n) N*=2; node.resize(N*2-1,-inf); } void update(int ind,int val){ ind+=N-1; node[ind]=val; while(ind){ ind=(ind-1)/2; node[ind]=std::max(node[ind*2+1],node[ind*2+2]); } } int Query(int left,int right,int now=0,int l=0,int r=-1){ if(r<0) r=N; if(left>=r||right<=l) return -inf; if(left<=l&&r<=right) return node[now]; return std::max(Query(left,right,now*2+1,l,(l+r)/2),Query(left,right,now*2+2,(l+r)/2,r)); } }; signed main(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); //入力、宣言 int N; cin>>N; vector<std::pair<int,int>> data; //data[i].second が 0 以下なら座標を、1 以上ならクエリを表す for(int i=0;i<N;i++){ int X; cin>>X; data.push_back(std::make_pair(X,-i)); } int Q; cin>>Q; vector<int> l(Q),r(Q); for(int i=0;i<Q;i++){ int x; cin>>l[i]>>r[i]>>x; data.push_back(std::make_pair(x,i+1)); } sort(data.begin(),data.end()); vector<int> ans(Q,inf); //本題 for(int _=0;_<2;_++){ Segtree seg(N); for(auto p:data){ if(p.second<=0) seg.update(-p.second,p.first); else{ int index=p.second-1; ans[index]=std::min(ans[index],p.first-seg.Query(l[index]-1,r[index])); } } for(auto &p:data) p.first*=-1; reverse(data.begin(),data.end()); } for(int i=0;i<Q;i++) cout<<ans[i]<<endl; }