結果

問題 No.2242 Cities and Teleporters
ユーザー roarisroaris
提出日時 2023-03-10 22:51:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,510 bytes
コンパイル時間 2,851 ms
コンパイル使用メモリ 213,680 KB
実行使用メモリ 40,728 KB
最終ジャッジ日時 2023-10-18 08:31:40
合計ジャッジ時間 14,402 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 289 ms
40,724 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 320 ms
40,436 KB
testcase_19 AC 403 ms
40,232 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 360 ms
39,136 KB
testcase_23 AC 345 ms
40,724 KB
testcase_24 AC 339 ms
40,724 KB
testcase_25 AC 403 ms
40,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vector<int> H, T;
    rep(i, N) {
        int Hi; cin >> Hi;
        H.push_back(Hi);
    }
    rep(i, N) {
        int Ti; cin >> Ti;
        T.push_back(Ti);
    }
    vector<vector<int>> HTI;
    rep(i, N) HTI.push_back({H[i], T[i], i});
    sort(HTI.begin(), HTI.end());
    int idx[N];
    rep(i, N) {
        H[i] = HTI[i][0];
        T[i] = HTI[i][1];
        idx[HTI[i][2]] = i;
    }
    
    int to[N+1];
    to[0] = 0;
    rep(v, N) to[v+1] = upper_bound(H.begin(), H.end(), T[v])-H.begin();
    
    int dp[30][N+1];
    dp[0][0] = 0;
    for (int v=1; v<=N; v++) dp[0][v] = max(dp[0][v-1], to[v]);
    for (int i=1; i<30; i++) rep(v, N) dp[i][v] = dp[i-1][dp[i-1][v]];
    
    int Q; cin >> Q;
    while (Q--) {
        int A, B; cin >> A >> B;
        A = idx[A-1]+1;
        B = idx[B-1]+1;
        int v = to[A];
        int ans;
        
        if (B<=v) ans = 1;
        else {
            int ok = N+10;
            int ng = -1;
            while (abs(ok-ng)>1) {
                int mid = (ok+ng)/2;
                int now = v;
                rep(i, 20) if ((mid>>i)&1) now = dp[i][now];
                if (B<=now) ok = mid;
                else ng = mid;
            }
            if (ok>N) ans = -1;
            else ans = ok+1;
        }
        
        printf("%d\n", ans);
    }
}
0