GerONSo

Untitled

Jun 8th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. #define pragma
  2.  
  3. #ifdef pragma
  4. #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
  5. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  6. #endif // pragma
  7.  
  8. #include<bits/stdc++.h>
  9. #include <ext/pb_ds/assoc_container.hpp>
  10. #include <ext/pb_ds/tree_policy.hpp>
  11.  
  12. #define ll long long
  13. #define all(x) begin(x), end(x)
  14. #define pb push_back
  15. #define x first
  16. #define y second
  17. //#define int long long
  18. #define zero(two) memset(two, 0, sizeof(two))
  19.  
  20. using namespace std;
  21. using namespace __gnu_pbds;
  22.  
  23.  
  24. typedef vector<int> vi;
  25. typedef vector<bool> vb;
  26. typedef pair<int, int> pii;
  27. typedef long double ld;
  28. typedef vector<vi> matrix;
  29. template<typename T>
  30. using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  31.  
  32. const ld PI = atan2(0, -1);
  33.  
  34. void seriy() {
  35. ios::sync_with_stdio(0);
  36. cin.tie(0);
  37. cout.tie(0);
  38. cout << fixed << setprecision(10);
  39. #if _offline
  40. freopen("input.txt", "r", stdin);
  41. freopen("output.txt", "w", stdout);
  42. #endif
  43. }
  44.  
  45. const int MAXN = 2e5 + 10;
  46. const int INF = 1e18 + 7;
  47. const int MAXLOG = 20;
  48. const int MOD = 998244353;
  49. const int BASE = 47;
  50. const int MAX = (1ll << 32) - 1;
  51.  
  52. struct node {
  53. int x, y, num;
  54. node *left = nullptr;
  55. node *right = nullptr;
  56.  
  57. node(int x1, int y1, int num1) {
  58. x = x1;
  59. y = y1;
  60. num = num1;
  61. }
  62. };
  63.  
  64. vector<node*> pr;
  65. node *lst;
  66.  
  67. void add(node *&kek, node *&cur) {
  68. // if(pr[kek -> num] != nullptr) cerr << cur -> num << " " << pr[kek -> num] -> num << '\n';
  69. if(kek -> y > cur -> y) {
  70. cur -> left = kek -> right;
  71. kek -> right = cur;
  72. pr[cur -> num] = kek;
  73. if(cur -> left != nullptr) pr[cur -> left -> num] = cur;
  74. return;
  75. }
  76. if(pr[kek -> num] == nullptr) {
  77. cur -> left = kek;
  78. pr[kek -> num] = cur;
  79. pr[cur -> num] = nullptr;
  80. return;
  81. }
  82. else {
  83. add(pr[kek -> num], cur);
  84. }
  85. }
  86.  
  87. signed main() {
  88. seriy();
  89. int n;
  90. cin >> n;
  91. pr.resize(n, nullptr);
  92. vector<pii> a;
  93. map<pii, int> lol;
  94. for(int i = 0; i < n; i++) {
  95. int x, y;
  96. cin >> x >> y;
  97. a.pb({x, y});
  98. lol[{x, y}] = i;
  99. }
  100. vi p;
  101. sort(all(a));
  102. for(int j = 0; j < n; j++) {
  103. p.pb(lol[a[j]]);
  104. }
  105. lst = new node(a[0].x, a[0].y, 0);
  106. vector<node*> ans;
  107. ans.pb(lst);
  108. for(int i = 1; i < n; i++) {
  109. node *cur = new node(a[i].x, a[i].y, i);
  110. add(lst, cur);
  111. ans.pb(cur);
  112. lst = cur;
  113. }
  114.  
  115. cout << "YES\n";
  116. vector<pair<pii, int>> res(n);
  117. for(int j = 0; j < n; j++) {
  118. int i = p[j];
  119. cerr << a[i].x << " " << a[i].y << '\n';
  120. 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)};
  121. }
  122. for(auto i : res) {
  123. cout << i.x.x << " " << i.x.y << " " << i.y << '\n';
  124. }
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment