#include 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 cd; seed_seq seq{ (uint64_t) chrono::duration_cast(chrono::high_resolution_clock::now().time_since_epoch()).count(), (uint64_t) __builtin_ia32_rdtsc(), (uint64_t) (uintptr_t) make_unique().get() }; mt19937 rng(seq); // mt19937_64 lrng(seq); struct debugger{ template debugger& operator<<(T &a){ #ifdef DEBUG cerr << a; #endif return *this; } template 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> a(n); vector hvalues(n); vector sortedh(n); vector 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 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<(a, b)(rng); -> bounds [a, b] num = uniform_real_distribution(a, b)(rng); -> bounds [a, b) can also instantiate distributions and call on generator: uniform_int_distribution 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); // } // };