Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define pragma
- #ifdef pragma
- #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
- //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #endif // pragma
- #include<bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ll long long
- #define all(x) begin(x), end(x)
- #define pb push_back
- #define x first
- #define y second
- //#define int long long
- #define zero(two) memset(two, 0, sizeof(two))
- using namespace std;
- using namespace __gnu_pbds;
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef pair<int, int> pii;
- typedef long double ld;
- typedef vector<vi> matrix;
- template<typename T>
- using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- const ld PI = atan2(0, -1);
- void seriy() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout << fixed << setprecision(10);
- #if _offline
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- const int MAXN = 2e5 + 10;
- const int INF = 1e18 + 7;
- const int MAXLOG = 20;
- const int MOD = 998244353;
- const int BASE = 47;
- const int MAX = (1ll << 32) - 1;
- struct node {
- int x, y, num;
- node *left = nullptr;
- node *right = nullptr;
- node(int x1, int y1, int num1) {
- x = x1;
- y = y1;
- num = num1;
- }
- };
- vector<node*> pr;
- node *lst;
- void add(node *&kek, node *&cur) {
- // if(pr[kek -> num] != nullptr) cerr << cur -> num << " " << pr[kek -> num] -> num << '\n';
- if(kek -> y > cur -> y) {
- cur -> left = kek -> right;
- kek -> right = cur;
- pr[cur -> num] = kek;
- if(cur -> left != nullptr) pr[cur -> left -> num] = cur;
- return;
- }
- if(pr[kek -> num] == nullptr) {
- cur -> left = kek;
- pr[kek -> num] = cur;
- pr[cur -> num] = nullptr;
- return;
- }
- else {
- add(pr[kek -> num], cur);
- }
- }
- signed main() {
- seriy();
- int n;
- cin >> n;
- pr.resize(n, nullptr);
- vector<pii> a;
- map<pii, int> lol;
- for(int i = 0; i < n; i++) {
- int x, y;
- cin >> x >> y;
- a.pb({x, y});
- lol[{x, y}] = i;
- }
- vi p;
- sort(all(a));
- for(int j = 0; j < n; j++) {
- p.pb(lol[a[j]]);
- }
- lst = new node(a[0].x, a[0].y, 0);
- vector<node*> ans;
- ans.pb(lst);
- for(int i = 1; i < n; i++) {
- node *cur = new node(a[i].x, a[i].y, i);
- add(lst, cur);
- ans.pb(cur);
- lst = cur;
- }
- cout << "YES\n";
- vector<pair<pii, int>> res(n);
- for(int j = 0; j < n; j++) {
- int i = p[j];
- cerr << a[i].x << " " << a[i].y << '\n';
- res[i] = {{((pr[i] == nullptr) ? 0 : p[pr[i] -> num] + 1), ((ans[i] -> left == nullptr) ? 0 : p[ans[i] -> left -> num] + 1)}, ((ans[i] -> right == nullptr) ? 0 : p[ans[i] -> right -> num] + 1)};
- }
- for(auto i : res) {
- cout << i.x.x << " " << i.x.y << " " << i.y << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment