結果

問題 No.2242 Cities and Teleporters
ユーザー srjywrdnprkt
提出日時 2025-03-26 00:15:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 552 ms / 3,000 ms
コード長 2,179 bytes
コンパイル時間 3,960 ms
コンパイル使用メモリ 291,532 KB
実行使用メモリ 23,752 KB
最終ジャッジ日時 2025-03-26 00:15:39
合計ジャッジ時間 14,090 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
//#include <atcoder/modint>
using namespace std;
//using namespace atcoder;
using ll = long long;
//using mint = modint998244353;
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
/*
iH_j<=T_ijT_j
kO(log k)
ATH_BO(log N)
*/
int N, mx=-1, argmx=-1;
cin >> N;
vector<int> H(N), T(N);
vector<pair<int, int>> v;
queue<pair<int, int>> que;
vector dp(20, vector<int>(N, -1));
for (int i=0; i<N; i++) cin >> H[i];
for (int i=0; i<N; i++){
cin >> T[i];
v.push_back({H[i], i});
}
sort(v.begin(), v.end());
for (auto &z : v) que.push(z);
v.clear();
for (int i=0; i<N; i++) v.push_back({T[i], i});
sort(v.begin(), v.end());
for (int i=0; i<N; i++){
while(!que.empty() && que.front().first <= v[i].first){
int x, y;
tie(x, y) = que.front();
que.pop();
if (T[y] > mx){
mx = T[y];
argmx = y;
}
}
dp[0][v[i].second] = argmx;
}
for (int i=1; i<20; i++){
for (int j=0; j<N; j++){
if (dp[i-1][j] != -1) dp[i][j] = dp[i-1][dp[i-1][j]];
}
}
int Q, s, t;
cin >> Q;
while(Q--){
cin >> s >> t;
s--; t--;
int ans=0;
if (H[t] <= T[s]) cout << 1 << '\n';
else{
for (int i=19; i>=0; i--){
if (dp[i][s] != -1 && T[dp[i][s]] < H[t]){
s = dp[i][s];
ans += (1<<i);
}
}
if (s == -1) cout << -1 << '\n';
else{
s = dp[0][s];
if (H[t] > T[s]) cout << -1 << '\n';
else cout << ans+2 << '\n';
}
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0