結果

問題 No.2242 Cities and Teleporters
ユーザー KKT89KKT89
提出日時 2023-03-10 23:32:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,278 bytes
コンパイル時間 3,126 ms
コンパイル使用メモリ 229,812 KB
実行使用メモリ 32,332 KB
最終ジャッジ日時 2023-10-18 09:14:24
合計ジャッジ時間 16,746 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 621 ms
31,664 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 590 ms
30,960 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 405 ms
32,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> h(n),t(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }
    vector<vector<int>> nx(20,vector<int>(n));
    vector<int> mx(n);
    vector<int> id(n);
    for (int i = 0; i < n; ++i) {
        id[i] = i;
    }
    sort(id.begin(), id.end(), [&](auto i,auto j){
        return h[i] < h[j];
    });
    auto v = h;
    sort(v.begin(), v.end());
    map<int,int> mp;
    for (int i = 0; i < n; ++i) {
        mp[h[i]] = i;
    }
    int u = 0;
    for (int _i = 0; _i < n; ) {
        int i = id[_i];
        int j = _i;
        while (_i < n and h[id[_i]] == h[i]) {
            u = max(u, t[id[_i]]);
            _i++;
        }
        auto it = lower_bound(v.begin(), v.end(), u);
        for (int k = j; k < _i; ++k) {
            if (it == v.begin()) {
                nx[0][id[k]] = id[k];
            }
            else {
                it--;
                nx[0][id[k]] = mp[*it];
                it++;
            }
        }
    }
    for (int i = 0; i+1 < 20; ++i) {
        for (int j = 0; j < n; ++j) {
            nx[i+1][j] = nx[i][nx[i][j]];
        }
    }
    int q; cin >> q;
    while (q--) {
        int a,b; cin >> a >> b;
        a--; b--;
        if (t[a] >= h[b]) {
            cout << 1 << "\n";
        }
        else {
            int cur = a;
            int res = 0;
            for (int k = 19; k >= 0; --k) {
                int nxt = cur;
                for (int i = k-1; i >= 0; --i) {
                    nxt = nx[i][nxt];
                    if (t[nxt] >= h[b]) break;
                }
                if (t[nxt] < h[b]) {
                    res += (1<<k);
                    cur = nx[k][cur];
                }
            }
            if (t[cur] >= h[b]) {
                cout << res+1 << "\n";
            }
            else {
                cout << -1 << "\n";
            }
        }
    }
}
0