結果
問題 | No.2242 Cities and Teleporters |
ユーザー | siganai |
提出日時 | 2023-03-12 16:56:52 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 8,217 bytes |
コンパイル時間 | 2,589 ms |
コンパイル使用メモリ | 217,432 KB |
実行使用メモリ | 28,592 KB |
最終ジャッジ日時 | 2024-09-18 07:05:26 |
合計ジャッジ時間 | 16,932 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 3 ms
6,940 KB |
testcase_03 | AC | 3 ms
6,944 KB |
testcase_04 | WA | - |
testcase_05 | AC | 920 ms
28,536 KB |
testcase_06 | AC | 598 ms
28,484 KB |
testcase_07 | AC | 843 ms
28,484 KB |
testcase_08 | AC | 1,272 ms
28,492 KB |
testcase_09 | AC | 1,314 ms
28,416 KB |
testcase_10 | AC | 341 ms
28,592 KB |
testcase_11 | AC | 288 ms
28,468 KB |
testcase_12 | AC | 283 ms
28,524 KB |
testcase_13 | AC | 448 ms
28,312 KB |
testcase_14 | AC | 591 ms
28,384 KB |
testcase_15 | AC | 415 ms
28,408 KB |
testcase_16 | AC | 457 ms
28,496 KB |
testcase_17 | AC | 789 ms
28,320 KB |
testcase_18 | AC | 361 ms
28,212 KB |
testcase_19 | AC | 463 ms
27,880 KB |
testcase_20 | AC | 371 ms
27,408 KB |
testcase_21 | AC | 291 ms
27,456 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
ソースコード
#line 1 "main.cpp" //#pragma GCC target("avx") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #ifdef LOCAL #include <debug.hpp> #define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) (static_cast<void>(0)) #endif using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>; using vpii = vector<pii>; using vpll = vector<pll>; using vs = vector<string>; template<class T> using pq = priority_queue<T, vector<T>, greater<T>>; #define overload4(_1, _2, _3, _4, name, ...) name #define overload3(a,b,c,name,...) name #define rep1(n) for (ll UNUSED_NUMBER = 0; UNUSED_NUMBER < (n); ++UNUSED_NUMBER) #define rep2(i, n) for (ll i = 0; i < (n); ++i) #define rep3(i, a, b) for (ll i = (a); i < (b); ++i) #define rep4(i, a, b, c) for (ll i = (a); i < (b); i += (c)) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep1(n) for(ll i = (n) - 1;i >= 0;i--) #define rrep2(i,n) for(ll i = (n) - 1;i >= 0;i--) #define rrep3(i,a,b) for(ll i = (b) - 1;i >= (a);i--) #define rrep4(i,a,b,c) for(ll i = (a) + ((b)-(a)-1) / (c) * (c);i >= (a);i -= c) #define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__) #define all1(i) begin(i) , end(i) #define all2(i,a) begin(i) , begin(i) + a #define all3(i,a,b) begin(i) + a , begin(i) + b #define all(...) overload3(__VA_ARGS__, all3, all2, all1)(__VA_ARGS__) #define sum(...) accumulate(all(__VA_ARGS__),0LL) template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; } template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; } template<class T> auto min(const T& a){ return *min_element(all(a)); } template<class T> auto max(const T& a){ return *max_element(all(a)); } template<class... Ts> void in(Ts&... t); #define INT(...) int __VA_ARGS__; in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; in(__VA_ARGS__) #define STR(...) string __VA_ARGS__; in(__VA_ARGS__) #define CHR(...) char __VA_ARGS__; in(__VA_ARGS__) #define DBL(...) double __VA_ARGS__; in(__VA_ARGS__) #define LD(...) ld __VA_ARGS__; in(__VA_ARGS__) #define VEC(type, name, size) vector<type> name(size); in(name) #define VV(type, name, h, w) vector<vector<type>> name(h, vector<type>(w)); in(name) ll intpow(ll a, ll b){ ll ans = 1; while(b){if(b & 1) ans *= a; a *= a; b /= 2;} return ans;} ll modpow(ll a, ll b, ll p){ ll ans = 1; a %= p;if(a < 0) a += p;while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll GCD(ll a,ll b) { if(a == 0 || b == 0) return 0; if(a % b == 0) return b; else return GCD(b,a%b);} ll LCM(ll a,ll b) { if(a == 0) return b; if(b == 0) return a;return a / GCD(a,b) * b;} namespace IO{ #define VOID(a) decltype(void(a)) struct setting{ setting(){cin.tie(nullptr); ios::sync_with_stdio(false);fixed(cout); cout.precision(12);}} setting; template<int I> struct P : P<I-1>{}; template<> struct P<0>{}; template<class T> void i(T& t){ i(t, P<3>{}); } void i(vector<bool>::reference t, P<3>){ int a; i(a); t = a; } template<class T> auto i(T& t, P<2>) -> VOID(cin >> t){ cin >> t; } template<class T> auto i(T& t, P<1>) -> VOID(begin(t)){ for(auto&& x : t) i(x); } template<class T, size_t... idx> void ituple(T& t, index_sequence<idx...>){ in(get<idx>(t)...);} template<class T> auto i(T& t, P<0>) -> VOID(tuple_size<T>{}){ ituple(t, make_index_sequence<tuple_size<T>::value>{});} #undef VOID } #define unpack(a) (void)initializer_list<int>{(a, 0)...} template<class... Ts> void in(Ts&... t){ unpack(IO :: i(t)); } #undef unpack static const double PI = 3.1415926535897932; template <class F> struct REC { F f; REC(F &&f_) : f(forward<F>(f_)) {} template <class... Args> auto operator()(Args &&...args) const { return f(*this, forward<Args>(args)...); }}; //constexpr int mod = 1000000007; constexpr int mod = 998244353; #line 2 "library/segtree/segtree.hpp" template <class S, S (*op)(S, S), S (*e)()> struct segtree { public: segtree() : segtree(0) {} explicit segtree(int n) : segtree(vector<S>(n, e())) {} explicit segtree(const vector<S>& v) : _n(int(v.size())) { log = 0; while ((1U << log) < (unsigned int)(_n)) log++; size = 1 << log; d = 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) const { assert(0 <= p && p < _n); return d[p + size]; } S prod(int l, int r) const { 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() const { return d[1]; } template <bool (*f)(S)> int max_right(int l) const { return max_right(l, [](S x) { return f(x); }); } template <class F> int max_right(int l, F f) const { 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) const { return min_left(r, [](S x) { return f(x); }); } template <class F> int min_left(int r, F f) const { 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; vector<S> d; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } }; #line 87 "main.cpp" using T = pii; T op(T x,T y) { if(x.first > y.first) return x; else return y; } T e() {return {-1,-1};} int main() { INT(n); VEC(int,h,n); VEC(int,t,n); vvi dv(20,vi(n)); vi H = h; sort(all(H)); vi ord(n); iota(all(ord),0); sort(all(ord),[&](int F,int S){return h[F] < h[S];}); vi invp(n); rep(i,n) invp[ord[i]] = i; vpii v(n); rep(i,n) { v[i].first = t[ord[i]]; v[i].second = ord[i]; } segtree<T,op,e> seg(v); rep(i,n) { int now = ord[i]; int id = upper_bound(all(H),t[now]) - H.begin(); auto ret = seg.prod(0,id); if(ret.first == -1) dv[0][now] = now; else dv[0][now] = ret.second; } rep(i,1,20) { rep(j,n) dv[i][j] = dv[i-1][dv[i-1][j]]; } INT(q); rep(i,q) { INT(a,b); a--,b--; int ok = n; int ng = -1; while(ok - ng > 1) { int mid = (ng + ok) / 2; int pos = a; rep(j,20) { if(mid >> j & 1) pos = dv[j][pos]; } if(t[pos] >= h[b]) ok = mid; else ng = mid; } if(ok == n) cout << -1 << '\n'; else cout << ok + 1 << '\n'; } }