#include using namespace std; #include #include using namespace atcoder; int op(int a, int b) { return max(a, b); } int e() { return -1e9; } int mapping(int f, int x) { return f + x; } int composition(int f, int g) { return f + g; } int id() { return 0; } int target; bool g(int x) { return x < target; } vector insertedA(vector &X, vector &Y) { int N = X.size(); vector P(N); for (int i = 0; i < N; i++) { P.at(i) = i; } lazy_segtree seg(P); vector A(N); for (int i = N - 1; i >= 0; i--) { target = Y.at(i); int r = seg.max_right(0); A.at(r) = X.at(i); seg.apply(r, N, -1); } return A; } int main() { int N; cin >> N; vector P(N); for (int i = 0; i < N; i++) { cin >> P.at(i); P.at(i)--; } vector Q(N); for (int i = 0; i < N; i++) { Q.at(P.at(i)) = i; } fenwick_tree fw(N); vector X(N), Y(N); int cnt = 0; for (int i = 0; i < N - 1; i++) { int y1 = fw.sum(0, Q.at(i)); int y2 = fw.sum(0, Q.at(i + 1)); if (y1 % 2 != 0 && y2 % 2 != 0) { cout << "No" << endl; cerr << i << endl; return 0; } if (y2 % 2 == 0) { if (y1 % 2 != 0 || Q.at(i) < Q.at(i + 1)) { swap(Q.at(i), Q.at(i + 1)); swap(y1, y2); if (y1 % 2 == 0) { cnt++; } } } X.at(i) = P.at(Q.at(i)); Y.at(i) = y1; fw.add(Q.at(i), 1); } X.back() = P.at(Q.back()); Y.back() = fw.sum(0, Q.back()); if (Y.back() % 2 != 0) { cout << "No" << endl; return 0; } cout << "Yes" << endl; for (int i = 0; i < N; i++) { cout << X.at(i) + 1 << " " << Y.at(i) + 1 << endl; } vector A = insertedA(X, Y); assert(P == A); }