結果
問題 | No.1332 Range Nearest Query |
ユーザー | penguinman |
提出日時 | 2020-11-23 04:13:40 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,790 bytes |
コンパイル時間 | 1,985 ms |
コンパイル使用メモリ | 179,188 KB |
実行使用メモリ | 12,276 KB |
最終ジャッジ日時 | 2023-09-30 23:16:46 |
合計ジャッジ時間 | 18,652 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 240 ms
9,216 KB |
testcase_04 | WA | - |
testcase_05 | AC | 231 ms
9,340 KB |
testcase_06 | AC | 201 ms
11,352 KB |
testcase_07 | AC | 200 ms
11,632 KB |
testcase_08 | AC | 200 ms
11,592 KB |
testcase_09 | AC | 200 ms
11,720 KB |
testcase_10 | AC | 203 ms
11,440 KB |
testcase_11 | AC | 203 ms
11,472 KB |
testcase_12 | AC | 201 ms
12,168 KB |
testcase_13 | AC | 207 ms
11,464 KB |
testcase_14 | AC | 203 ms
11,752 KB |
testcase_15 | AC | 204 ms
11,424 KB |
testcase_16 | AC | 258 ms
11,384 KB |
testcase_17 | AC | 253 ms
11,988 KB |
testcase_18 | AC | 252 ms
11,556 KB |
testcase_19 | AC | 251 ms
11,596 KB |
testcase_20 | AC | 253 ms
11,440 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 255 ms
11,436 KB |
testcase_25 | AC | 255 ms
11,804 KB |
testcase_26 | AC | 163 ms
11,696 KB |
testcase_27 | AC | 138 ms
11,364 KB |
testcase_28 | AC | 44 ms
5,212 KB |
testcase_29 | AC | 46 ms
5,196 KB |
testcase_30 | AC | 48 ms
5,064 KB |
testcase_31 | AC | 40 ms
5,312 KB |
testcase_32 | AC | 51 ms
5,088 KB |
testcase_33 | AC | 52 ms
5,128 KB |
testcase_34 | AC | 42 ms
5,136 KB |
testcase_35 | AC | 45 ms
5,048 KB |
testcase_36 | AC | 44 ms
5,152 KB |
testcase_37 | AC | 47 ms
5,068 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 242 ms
11,576 KB |
testcase_41 | WA | - |
testcase_42 | AC | 187 ms
8,232 KB |
testcase_43 | WA | - |
testcase_44 | AC | 220 ms
9,072 KB |
testcase_45 | WA | - |
testcase_46 | AC | 174 ms
7,168 KB |
testcase_47 | WA | - |
ソースコード
#include<bits/stdc++.h> using std::cin; using std::cout; using std::vector; using ll=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)); } }; int 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; }