結果
問題 | No.2242 Cities and Teleporters |
ユーザー | ttkkggww |
提出日時 | 2023-03-11 01:39:02 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,806 ms / 3,000 ms |
コード長 | 2,154 bytes |
コンパイル時間 | 4,824 ms |
コンパイル使用メモリ | 275,324 KB |
実行使用メモリ | 64,592 KB |
最終ジャッジ日時 | 2023-10-18 09:31:34 |
合計ジャッジ時間 | 25,174 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
48,712 KB |
testcase_01 | AC | 11 ms
48,708 KB |
testcase_02 | AC | 11 ms
48,712 KB |
testcase_03 | AC | 11 ms
48,712 KB |
testcase_04 | AC | 11 ms
48,712 KB |
testcase_05 | AC | 1,393 ms
64,592 KB |
testcase_06 | AC | 1,395 ms
64,592 KB |
testcase_07 | AC | 1,412 ms
64,592 KB |
testcase_08 | AC | 1,806 ms
64,592 KB |
testcase_09 | AC | 1,150 ms
64,592 KB |
testcase_10 | AC | 311 ms
64,592 KB |
testcase_11 | AC | 412 ms
64,592 KB |
testcase_12 | AC | 414 ms
64,592 KB |
testcase_13 | AC | 609 ms
64,592 KB |
testcase_14 | AC | 1,196 ms
64,592 KB |
testcase_15 | AC | 606 ms
64,592 KB |
testcase_16 | AC | 625 ms
64,592 KB |
testcase_17 | AC | 1,318 ms
64,592 KB |
testcase_18 | AC | 426 ms
64,448 KB |
testcase_19 | AC | 560 ms
64,392 KB |
testcase_20 | AC | 535 ms
63,980 KB |
testcase_21 | AC | 452 ms
64,068 KB |
testcase_22 | AC | 463 ms
63,956 KB |
testcase_23 | AC | 505 ms
64,592 KB |
testcase_24 | AC | 502 ms
64,592 KB |
testcase_25 | AC | 498 ms
64,592 KB |
ソースコード
#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; maxt[i]--; if(i){ maxt[i] =max(maxt[i-1],maxt[i]); maxt[i] =max(maxt[i],i); } //cout<<maxt[i]<<' '; } //cout<<endl; } 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(); T[idx]--; } } for(ll i = 0;i<q;i++){ auto [lidx,ridx] = ab[i]; auto lH = T[lidx]; auto rH = H[ridx]; //cout<<lH<<' '<<rH<<' '<<f_to(lH,n*3)<<endl; if(lH==-1){ cout<<-1<<endl; continue; } if(lH==rH){ cout<<1<<endl; continue; } 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<<'\n'; }else{ cout<<-1<<'\n'; } } } 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(); }