結果

問題 No.2242 Cities and Teleporters
ユーザー Jerry LiJerry Li
提出日時 2023-12-24 11:15:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,149 bytes
コンパイル時間 2,374 ms
コンパイル使用メモリ 188,708 KB
実行使用メモリ 45,840 KB
最終ジャッジ日時 2023-12-24 11:16:04
合計ジャッジ時間 11,114 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,676 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 3 ms
6,676 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 236 ms
45,464 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 224 ms
45,172 KB
testcase_23 AC 228 ms
45,628 KB
testcase_24 AC 230 ms
45,640 KB
testcase_25 AC 232 ms
45,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long
typedef int uci;
#define int long long
#define F first
#define S second
typedef complex<double> cd;

seed_seq seq{
    (uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(),
    (uint64_t) __builtin_ia32_rdtsc(),
    (uint64_t) (uintptr_t) make_unique<char>().get()
};
mt19937 rng(seq);
// mt19937_64 lrng(seq);

struct debugger{
    template <typename T>
    debugger& operator<<(T &a){
        #ifdef DEBUG
            cerr << a;
        #endif
        return *this;
    }
    template <typename T>
    debugger& operator<<(T &&a){
        #ifdef DEBUG
            cerr << a;
        #endif
        return *this;
    }
} deb;

const double PI = acos(-1.0);
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

//! function insert

//THINK FIRST, CODE SECOND
//DON'T GET STUCK ON ONE STRATEGY
//CALM DOWNNN FOR ONCE IN YOUR LIFE
//REDUCE
//COUGH E??!?!?!! O.O
//uwu i see you ryan

int lift[200001][20];
void solve() {
    int n;
    cin >> n;
    vector<ar<int, 3>> a(n);
    vector<int> hvalues(n);
    vector<int> sortedh(n);
    vector<int> tvalues(n);
    for(int i{}; i < n; ++i){
        cin >> a[i][0];
        hvalues[i] = a[i][0];
        sortedh[i] = a[i][0];
        a[i][2] = i;
    }
    for(int i{}; i < n; ++i){
        cin >> a[i][1];
        tvalues[i] = a[i][1];
    }

    sort(sortedh.begin(), sortedh.end());
    sort(a.begin(), a.end());
    vector<int> best(n);
    int curr = a[0][1];
    best[0] = a[0][2];
    for(int i{1}; i < n; ++i){
        if(a[i][1] > curr){
            curr = a[i][1];
            best[i] = a[i][2];
        }else
            best[i] = best[i-1];
    }

    sort(a.begin(), a.end(), [](auto b, auto c){
            return b[1] < c[1];
            });
    for(int i = n-1; i >= 0; --i){
        int p = upper_bound(sortedh.begin(), sortedh.end(), a[i][1]) - sortedh.begin();
        p--;
        if(p < 0 || tvalues[best[p]] == tvalues[a[i][2]]){
            for(int j{}; j < 20; ++j)
                lift[a[i][2]][j] = a[i][2];
        }else{
            lift[a[i][2]][0] = best[p];
            for(int j{1}; j < 20; ++j){
                lift[a[i][2]][j] = lift[lift[a[i][2]][j-1]][j-1];
            }
        }
    }
    
    int q;
    cin >> q;
    while(q--){
        int a, b;
        cin >> a >> b;
        a--, b--;

        if(tvalues[a] >= hvalues[b]){
            cout << 1 << '\n';
        }else{
            int steps{};
            for(int j = 19; j >= 0; --j){
                if(tvalues[lift[a][j]] < hvalues[b]){
                    steps += 1<<j;
                    a = lift[a][j];
                }
            }
            if(tvalues[lift[a][0]] < hvalues[b])
                cout << -1 << '\n';
            else
                cout << steps+1 << '\n';
        }
    }
}

uci main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

        // cout << "Case #" << t  << ": ";
        solve();
}

/*
    random number generator stuff
    num = rng(); gives integer number
    num = uniform_int_distribution<int>(a, b)(rng); -> bounds [a, b]
    num = uniform_real_distribution<double>(a, b)(rng); -> bounds [a, b)
    can also instantiate distributions and call on generator:
    uniform_int_distribution<int> thing(a, b);
    num = thing(rng);
*/
// struct custom_hash {
//     static uint64_t splitmix64(uint64_t x) {
//         // http://xorshift.di.unimi.it/splitmix64.c
//         x += 0x9e3779b97f4a7c15;
//         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//         return x ^ (x >> 31);
//     }
//     size_t operator()(uint64_t x) const {
//         static const uint64_t FIXED_RANDOM = lrng();
//         return splitmix64(x + FIXED_RANDOM);
//     }
// };
0