結果

問題 No.2242 Cities and Teleporters
ユーザー cho435cho435
提出日時 2023-03-11 01:30:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,250 bytes
コンパイル時間 3,126 ms
コンパイル使用メモリ 213,620 KB
実行使用メモリ 40,968 KB
最終ジャッジ日時 2023-10-18 09:29:26
合計ジャッジ時間 15,253 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 RE -
testcase_05 AC 510 ms
40,924 KB
testcase_06 AC 454 ms
40,924 KB
testcase_07 AC 513 ms
40,924 KB
testcase_08 AC 666 ms
40,924 KB
testcase_09 AC 497 ms
40,924 KB
testcase_10 AC 240 ms
40,924 KB
testcase_11 AC 405 ms
40,924 KB
testcase_12 AC 413 ms
40,924 KB
testcase_13 AC 429 ms
40,924 KB
testcase_14 AC 483 ms
40,924 KB
testcase_15 AC 435 ms
40,924 KB
testcase_16 AC 501 ms
40,924 KB
testcase_17 AC 617 ms
40,924 KB
testcase_18 RE -
testcase_19 AC 687 ms
40,132 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<int(n);i++)

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vector<vector<int>> ht(n,vector<int>(3));
  rep(i,n) cin>>ht.at(i).at(0);
  rep(i,n) cin>>ht.at(i).at(1);
  rep(i,n) ht.at(i).at(2)=i;
  sort(ht.begin(),ht.end());
  vector<int> p(n);
  rep(i,n) p.at(ht.at(i).at(2))=i;
  vector<int> cnd(n+1,-1);
  vector<int> cph(n);
  rep(i,n) cph.at(i)=ht.at(i).at(0);
  rep(i,n){
    auto it=upper_bound(cph.begin(),cph.end(),ht.at(i).at(1));
    cnd.at(i+1)=max(cnd.at(i),int(it-cph.begin()-1));
  }
  vector<vector<int>> ddv(30,vector<int>(n));
  rep(i,n) ddv.at(0).at(i)=cnd.at(i+1);
  rep(i,29){
    rep(j,n){
      ddv.at(i+1).at(j)=ddv.at(i).at(ddv.at(i).at(j));
    }
  }
  int q;
  cin>>q;
  rep(Qi,q){
    int a,b;
    cin>>a>>b;
    a--; b--;
    int na=p.at(a),nb=p.at(b);
    int ans=1;
    na=upper_bound(cph.begin(),cph.end(),ht.at(na).at(1))-cph.begin()-1;
    if(na<nb){
      for(int i=29;i>=0;i--){
        if(ddv.at(i).at(na)<nb){
          na=ddv.at(i).at(na);
          ans+=1<<i;
        }
      }
      na=ddv.at(0).at(na);
      ans++;
      if(na<nb) ans=-1;
    }
    cout<<ans<<'\n';
  }
}
0