// compile: g++ -o data data.cpp -O3 -std=gnu++20 -Wall -Wextra -Wshadow -D_GLIBCXX_ASSERTIONS -ggdb3 -fmax-errors=2 -DLOCAL
// run: ./data < data.in
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#ifdef LOCAL
#include <debug/codeforces.h>
#define debug(x...) {_variables(#x);_print(x);}
#else
#define debug(x...)
#endif
template<typename...Args> void print_(Args...args){((cout<<args<<" "),...)<<endl;}
#define rep(i,a,b) for(int i=(a);i<(int)(b);++i)
#define sz(v) ((int)(v).size())
#define print(...) print_(__VA_ARGS__);
#define INTMAX (int)(9223372036854775807)
#define INTINF (int)(1152921504606846976)
#define int long long
#define MAXN 200010
int n;
int P[MAXN], I[MAXN], L[MAXN], R[MAXN];
int *pos[MAXN];
bool valid = 1;
int build(int *pl, int *pr, int *il, int *ir) {
if (pl > pr || il > ir) return -1;
int root = *pl;
int *mid = pos[root];
if (mid > ir || mid < il) {
valid = 0;
return -1;
}
debug(pl-P, pr-P, il-I, ir-I)
int sz = mid - il;
L[root] = build(pl+1, pl+sz, il, mid - 1);
R[root] = build(pl+sz+1, pr, mid + 1, ir);
return root;
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n;
rep(i, 0, n) cin >> P[i], --P[i];
rep(i, 0, n) cin >> I[i], --I[i];
memset(pos, 0, sizeof(pos));
rep(i, 0, n) pos[I[i]] = I + i;
int root = build(P, P+n-1, I, I+n-1);
if (!valid || root) {
cout << -1 << endl;
return 0;
}
rep(i, 0, n) cout << L[i]+1 << " " << R[i]+1 << endl;
return 0;
}
Sup! I’m checking 666d.info. Just found this 666d, is anyone playing it? 666d
Goldenhoyeah1’s got a certain charm to it, you know? The graphics are pretty decent, and the games are easy to pick up. Good for a casual gaming session. Feel like a fun time? Give it a shot: goldenhoyeah1
Alright, Acesupercom… let’s see what you’ve got. Hopefully not another disappointment! Going in with an open mind. Anyone had any lucky wins on here? Explore it yourself: acesupercom
7gggbet? Hmm. I gave it a try, and honestly, it’s kinda average. The variety of games could be better, but the platform itself seems secure enough. Give it a look if you’re feeling adventurous: 7gggbet
vnlmxcasino, huh? Let’s see if the games are any good and the payouts are fair. Might stick around if its legit. Check this out vnlmxcasino
Checking out wjpesologin. Seems easy enough to use. Hopefully it works smoothly. I might stick around a while. Give it a try wjpesologin