結果
問題 | No.2242 Cities and Teleporters |
ユーザー | t98slider |
提出日時 | 2023-03-10 23:10:25 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 367 ms / 3,000 ms |
コード長 | 5,768 bytes |
コンパイル時間 | 1,823 ms |
コンパイル使用メモリ | 178,216 KB |
実行使用メモリ | 40,732 KB |
最終ジャッジ日時 | 2024-09-18 05:20:38 |
合計ジャッジ時間 | 9,829 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 242 ms
23,576 KB |
testcase_06 | AC | 221 ms
23,584 KB |
testcase_07 | AC | 238 ms
23,580 KB |
testcase_08 | AC | 296 ms
23,580 KB |
testcase_09 | AC | 255 ms
23,412 KB |
testcase_10 | AC | 197 ms
40,732 KB |
testcase_11 | AC | 232 ms
40,600 KB |
testcase_12 | AC | 249 ms
40,604 KB |
testcase_13 | AC | 244 ms
40,604 KB |
testcase_14 | AC | 264 ms
40,604 KB |
testcase_15 | AC | 258 ms
40,608 KB |
testcase_16 | AC | 290 ms
40,604 KB |
testcase_17 | AC | 327 ms
40,604 KB |
testcase_18 | AC | 241 ms
40,176 KB |
testcase_19 | AC | 367 ms
40,032 KB |
testcase_20 | AC | 236 ms
39,056 KB |
testcase_21 | AC | 241 ms
39,200 KB |
testcase_22 | AC | 302 ms
39,060 KB |
testcase_23 | AC | 282 ms
40,568 KB |
testcase_24 | AC | 254 ms
40,732 KB |
testcase_25 | AC | 218 ms
40,600 KB |
ソースコード
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define codefor int test;cin>>test;while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) using namespace std; using ll = long long; template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>; template<class T> istream& operator>>(istream& is, vector<T>& vec) {for(T& x : vec)is >> x;return is;} template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) {if(vec.empty())return os;os << vec[0];for(auto it = vec.begin(); ++it!= vec.end();)os << ' ' << *it;return os;} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){cin >> head;in(tail...);} void out(){cout << '\n';} template<class T>void out(const T& a){cout << a << '\n';} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){cout << head << ' ';out(tail...);} const int INF = 1 << 30; const long long INF2 = 1ll << 60; template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} template <class S, S (*op)(S, S), S (*e)()> struct segtree { public: segtree() : segtree(0) {} segtree(int n) : segtree(std::vector<S>(n, e())) {} segtree(const std::vector<S>& v) : _n(int(v.size())) { log = ceil_pow2(_n); size = 1 << log; d = std::vector<S>(2 * size, e()); for (int i = 0; i < _n; i++) d[size + i] = v[i]; for (int i = size - 1; i >= 1; i--) { update(i); } } void set(int p, S x) { assert(0 <= p && p < _n); p += size; d[p] = x; for (int i = 1; i <= log; i++) update(p >> i); } S get(int p) { assert(0 <= p && p < _n); return d[p + size]; } const S operator[](int p) const { return get(p); } S operator[](int p) { return get(p); } S prod(int l, int r) { assert(0 <= l && l <= r && r <= _n); S sml = e(), smr = e(); l += size; r += size; while (l < r) { if (l & 1) sml = op(sml, d[l++]); if (r & 1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } S all_prod() { return d[1]; } template <bool (*f)(S)> int max_right(int l) { return max_right(l, [](S x) { return f(x); }); } template <class F> int max_right(int l, F f) { assert(0 <= l && l <= _n); assert(f(e())); if (l == _n) return _n; l += size; S sm = e(); do { while (l % 2 == 0) l >>= 1; if (!f(op(sm, d[l]))) { while (l < size) { l = (2 * l); if (f(op(sm, d[l]))) { sm = op(sm, d[l]); l++; } } return l - size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } template <bool (*f)(S)> int min_left(int r) { return min_left(r, [](S x) { return f(x); }); } template <class F> int min_left(int r, F f) { assert(0 <= r && r <= _n); assert(f(e())); if (r == 0) return 0; r += size; S sm = e(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!f(op(d[r], sm))) { while (r < size) { r = (2 * r + 1); if (f(op(d[r], sm))) { sm = op(d[r], sm); r--; } } return r + 1 - size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } private: int _n, size, log; std::vector<S> d; int ceil_pow2(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } }; int op(int lhs, int rhs){ return max(lhs, rhs); } int e(){ return 0; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> ca, h(n), t(n); cin >> h >> t; ca = h; ca.insert(ca.end(), all(t)); sort(all(ca)); ca.erase(unique(all(ca)), ca.end()); vector<int> mx(ca.size()); for(int i = 0; i < n; i++){ h[i] = lower_bound(ca.begin(), ca.end(), h[i]) - ca.begin(); t[i] = lower_bound(ca.begin(), ca.end(), t[i]) - ca.begin(); chmax(mx[h[i]], t[i]); } //cerr << h << '\n'; //cerr << t << '\n'; //segtree<int, op, e> seg(mx); vector<vector<int>> dp(20, vector<int>(ca.size())); int mxv = 0; for(int i = 0; i < ca.size(); i++){ chmax(mxv, mx[i]); dp[0][i] = mxv; } for(int i = 1; i < 20; i++){ for(int j = 0; j < ca.size(); j++){ dp[i][j] = dp[i - 1][dp[i - 1][j]]; } } int Q; cin >> Q; while(Q--){ int u, v; cin >> u >> v; u--, v--; if(h[v] <= t[u]){ out(1); continue; } int ans = 0, cur = t[u]; for(int i = 19; i >= 0; i--){ if(dp[i][cur] < h[v]){ cur = dp[i][cur]; ans += 1 << i; } } if(ans >= n) ans = -1; else ans += 2; out(ans); } }