結果
問題 | No.2242 Cities and Teleporters |
ユーザー | ttkkggww |
提出日時 | 2023-03-11 01:01:00 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,970 bytes |
コンパイル時間 | 6,303 ms |
コンパイル使用メモリ | 273,500 KB |
実行使用メモリ | 64,660 KB |
最終ジャッジ日時 | 2023-10-18 09:25:59 |
合計ジャッジ時間 | 25,021 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
48,712 KB |
testcase_01 | AC | 11 ms
48,708 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 11 ms
48,712 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 639 ms
64,592 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
ソースコード
#include<bits/stdc++.h> using namespace std; #include<atcoder/all> using namespace atcoder; using ll = long long; ll n; using TUP = tuple<ll,ll,ll>; ll q; ll dp[30][202020];//dp[i][j]:= 2^i解移動した時の最大の標高(未満) using P = pair<ll,ll>; vector<TUP> vtup; vector<P> ab; ll f_to(ll st,ll x){ for(ll i = 0;i<30;i++){ if(x>>i&1){ st = dp[i][st]; } } return st; } void solve(){ sort(vtup.begin(),vtup.end()); vector<ll> maxt(n); { vector<ll> H(n); for(ll i = 0;i<n;i++){ auto [h,t,idx] = vtup[i]; H[i] = h; } for(ll i = 0;i<n;i++){ auto [h,t,idx] = vtup[i]; auto it = upper_bound(H.begin(),H.end(),t) - H.begin(); maxt[i] = it; if(i){ maxt[i] =max(maxt[i-1],maxt[i]); } } } for(ll i = 0;i<30;i++){ if(i==0){ for(ll j = 0;j<n;j++){ dp[i][j] = maxt[j]; } }else{ for(ll j = 0;j<n;j++){ auto [h,t,idx] = vtup[j]; dp[i][j] = dp[i-1][dp[i-1][j]]; } } } vector<ll> H(n); for(ll i = 0;i<n;i++){ auto [h,t,idx] = vtup[i]; H[idx] = i; } vector<ll> T(n); { vector<ll> H(n); for(ll i = 0;i<n;i++){ auto [h,t,idx] = vtup[i]; H[i] = h; } for(ll i = 0;i<n;i++){ auto [h,t,idx] = vtup[i]; T[idx] = upper_bound(H.begin(),H.end(),t)-H.begin(); } } for(ll i = 0;i<q;i++){ auto [lidx,ridx] = ab[i]; auto lH = H[lidx]; auto rH = H[ridx]; lH = T[lidx]; //cout<<lH<<' '<<rH<<' '<<f_to(lH,0)<<endl; if(rH<f_to(lH,n*3)){ ll ng = -1,ok = n*3; while(abs(ok-ng)>1){ ll mid = (ng+ok)/2; if(rH<f_to(lH,mid))ok = mid; else ng = mid; } cout<<ok+1<<endl; }else{ cout<<-1<<endl; } } } signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cin >> n; vtup = vector<TUP>(n); for(auto &[h,t,i]:vtup)cin >> h; for(auto &[h,t,i]:vtup)cin >> t; for(ll i = 0;i<n;i++){ auto &[h,t,idx] = vtup[i]; idx = i; } cin >> q; ab = vector<P>(q); for(auto &[a,b]:ab)cin >> a >> b; for(auto &[a,b]:ab)a--,b--; solve(); }