結果

問題 No.2242 Cities and Teleporters
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-08-08 20:39:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 908 ms / 3,000 ms
コード長 1,392 bytes
コンパイル時間 7,343 ms
コンパイル使用メモリ 336,932 KB
実行使用メモリ 26,112 KB
最終ジャッジ日時 2024-04-26 13:05:34
合計ジャッジ時間 26,154 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 769 ms
26,112 KB
testcase_06 AC 774 ms
26,112 KB
testcase_07 AC 770 ms
26,112 KB
testcase_08 AC 908 ms
26,112 KB
testcase_09 AC 721 ms
26,112 KB
testcase_10 AC 652 ms
26,112 KB
testcase_11 AC 678 ms
25,984 KB
testcase_12 AC 668 ms
25,984 KB
testcase_13 AC 680 ms
25,984 KB
testcase_14 AC 723 ms
26,112 KB
testcase_15 AC 682 ms
26,112 KB
testcase_16 AC 710 ms
26,112 KB
testcase_17 AC 778 ms
26,112 KB
testcase_18 AC 589 ms
25,600 KB
testcase_19 AC 585 ms
25,600 KB
testcase_20 AC 652 ms
24,960 KB
testcase_21 AC 669 ms
24,960 KB
testcase_22 AC 595 ms
25,088 KB
testcase_23 AC 677 ms
26,112 KB
testcase_24 AC 624 ms
26,112 KB
testcase_25 AC 626 ms
25,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
  int n;cin>>n;
  vc<pair<int,pp>>hh(n); rep(i,n)cin>>hh[i].fi; rep(i,n)cin>>hh[i].se.fi;
  rep(i,n)hh[i].se.se=i; sort(all(hh));
  vc<int>h(n),t(n); rep(i,n)h[i]=hh[i].fi,t[i]=hh[i].se.fi;
  vc<int>r(n); rep(i,n)r[hh[i].se.se]=i;
  vc<int>rr(n); rep(i,n)rr[i]=hh[i].se.se;
  vc<int>v(n);
  rep(i,n){
    int it=upper_bound(all(h),t[i])-h.begin();
    it--;
    v[i]=it;
  }
  vc vx(20,vc<int>(n)); vx[0]=v;
  rep(i,n-1)vx[0][i+1]=max(vx[0][i+1],vx[0][i]);
  rep(i,19)rep(j,n)if(vx[i][j]!=-1)vx[i+1][j]=vx[i][vx[i][j]];
  int q;cin>>q;
  rep(z,q){
    int a,b;cin>>a>>b; a--;b--;
    a=r[a],b=r[b];
    if(v[a]==-1){
      cout<<-1<<"\n";
      continue;
    }
    if(b<=v[a]){
      cout<<1<<"\n";
      continue;
    }
    a=v[a];
    if(b>vx[19][a]){
      cout<<-1<<"\n";
      continue;
    }
    int res=0;
    for(int i=19;i>=0;i--){
      int na=vx[i][a];
      if(na<b){
        res+=1<<i;
        a=na;
      }
    }
    cout<<res+2<<"\n";
  }
}
      
  
	
0