結果
| 問題 |
No.2242 Cities and Teleporters
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-24 11:15:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,149 bytes |
| コンパイル時間 | 2,449 ms |
| コンパイル使用メモリ | 188,460 KB |
| 実行使用メモリ | 45,652 KB |
| 最終ジャッジ日時 | 2024-09-27 13:40:58 |
| 合計ジャッジ時間 | 10,442 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 19 |
ソースコード
#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);
// }
// };