結果
問題 | No.2242 Cities and Teleporters |
ユーザー | Jerry Li |
提出日時 | 2023-12-24 11:17:37 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 489 ms / 3,000 ms |
コード長 | 4,149 bytes |
コンパイル時間 | 2,450 ms |
コンパイル使用メモリ | 188,568 KB |
実行使用メモリ | 45,608 KB |
最終ジャッジ日時 | 2024-09-27 13:41:10 |
合計ジャッジ時間 | 10,881 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 379 ms
45,480 KB |
testcase_06 | AC | 305 ms
45,432 KB |
testcase_07 | AC | 386 ms
45,372 KB |
testcase_08 | AC | 489 ms
45,352 KB |
testcase_09 | AC | 455 ms
45,372 KB |
testcase_10 | AC | 240 ms
45,608 KB |
testcase_11 | AC | 223 ms
45,376 KB |
testcase_12 | AC | 222 ms
45,392 KB |
testcase_13 | AC | 229 ms
45,500 KB |
testcase_14 | AC | 248 ms
45,480 KB |
testcase_15 | AC | 233 ms
45,500 KB |
testcase_16 | AC | 235 ms
45,488 KB |
testcase_17 | AC | 269 ms
45,604 KB |
testcase_18 | AC | 210 ms
44,860 KB |
testcase_19 | AC | 227 ms
44,560 KB |
testcase_20 | AC | 218 ms
43,728 KB |
testcase_21 | AC | 221 ms
43,792 KB |
testcase_22 | AC | 230 ms
43,660 KB |
testcase_23 | AC | 223 ms
45,424 KB |
testcase_24 | AC | 233 ms
45,516 KB |
testcase_25 | AC | 236 ms
45,400 KB |
ソースコード
#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+2 << '\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); // } // };