Advertisement
GerONSo

Untitled

Aug 27th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. /*
  2. --┬-- | | --┬-- | |
  3. | |\ | | | |
  4. | | \ | | -----> | |
  5. | | \ | | | |
  6. | | \ | | | |
  7. --┴-- | \| | └---- └----
  8.  
  9. */
  10.  
  11. #define pragma
  12.  
  13. #ifdef pragma
  14. #pragma GCC optimize("Ofast")
  15. #pragma GCC optimize("no-stack-protector")
  16. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  17. #pragma GCC optimize("unroll-loops")
  18. #endif // pragma
  19.  
  20. #include<bits/stdc++.h>
  21.  
  22. #define ll long long
  23. #define all(x) begin(x),end(x)
  24. #define pb push_back
  25. #define x first
  26. #define y second
  27. #define int long long
  28.  
  29. using namespace std;
  30.  
  31. typedef vector<int> vi;
  32. typedef vector<bool> vb;
  33. typedef pair<int,int> pii;
  34. typedef long double ld;
  35. typedef vector<vi> matrix;
  36.  
  37. const int INF = 1e18 + 7;
  38. const int MAXN = 1e6 + 7;
  39. const ld EPS = 1e-9;
  40. const ld PI = atan2(0, -1);
  41.  
  42. void seriy() {
  43. ios::sync_with_stdio(0);
  44. cin.tie(0);
  45. cout.tie(0);
  46. // cout << fixed << setprecision(6);
  47. #if 1
  48. freopen("input", "r", stdin);
  49. freopen("output", "w", stdout);
  50. #endif
  51. }
  52.  
  53. struct pt {
  54. int x, y;
  55. };
  56.  
  57. struct rect {
  58. pt l, r;
  59. int w;
  60. };
  61.  
  62. struct event {
  63. int x, top, bot, w, pos, t;
  64. };
  65.  
  66. istream& operator>>(istream& is, pt& p) {
  67. is >> p.x >> p.y;
  68. return is;
  69. }
  70.  
  71. ostream& operator<<(ostream& os, pt& p) {
  72. os << p.x << " " << p.y;
  73. return os;
  74. }
  75.  
  76. vector<pii> t(4 * MAXN, {0, -1});
  77. vector<int> upd(MAXN, -1);
  78.  
  79. pii get(int v, int tl, int tr, int l, int r) {
  80. if(tl > r || tr < l) {
  81. return {-INF, -1};
  82. }
  83. if(tl >= l && tr <= r) {
  84. return t[v];
  85. }
  86. int tm = (tl + tr) >> 1;
  87. pii x = get(v * 2 + 1, tl, tm, l, r);
  88. pii y = get(v * 2 + 2, tm + 1, tr, l, r);
  89. if(x.x > y.x) {
  90. return x;
  91. }
  92. else {
  93. return y;
  94. }
  95. // return max(x, y);
  96. }
  97.  
  98. void update(int v, int tl, int tr, int x, int val, int num) {
  99. if(x > tr || x < tl) {
  100. return;
  101. }
  102. if(tl == tr) {
  103. if(val > t[v].x) {
  104. t[v] = {val, num};
  105. }
  106. upd[num] = t[v].x;
  107. // upd[tl].y = num;
  108. return;
  109. }
  110. int tm = (tl + tr) >> 1;
  111. update(v * 2 + 1, tl, tm, x, val, num);
  112. update(v * 2 + 2, tm + 1, tr, x, val, num);
  113. t[v] = ((t[v * 2 + 1].x > t[v * 2 + 2].x) ? t[v * 2 + 1] : t[v * 2 + 2]);
  114. }
  115.  
  116. bool cmp(event a, event b) {
  117. return a.x < b.x || a.x == b.x && a.t < b.t;
  118. }
  119.  
  120. signed main() {
  121. seriy();
  122. int n;
  123. cin >> n;
  124. vector<rect> rects(n);
  125. map<int, int> ys;
  126. map<int, int> xs;
  127. map<int, int> ysr;
  128. map<int, int> xsr;
  129. vi yy;
  130. int num = 1, num1 = 1;
  131. for(int i = 0; i < n; i++) {
  132. cin >> rects[i].l >> rects[i].r >> rects[i].w;
  133. rects[i].l.x += 1e9;
  134. rects[i].l.y += 1e9;
  135. rects[i].r.x += 1e9;
  136. rects[i].r.y += 1e9;
  137. yy.pb(rects[i].l.y);
  138. yy.pb(rects[i].r.y);
  139. }
  140. sort(all(yy));
  141. for(int i = 0; i < yy.size(); i++) {
  142. if(ysr[yy[i]] == 0) {
  143. ys[num] = yy[i];
  144. ysr[yy[i]] = num;
  145. num++;
  146. }
  147. }
  148. vector<event> evs;
  149. for(int i = 0; i < n; i++) {
  150. evs.pb({rects[i].l.x, ysr[rects[i].r.y], ysr[rects[i].l.y], rects[i].w, i, -1});
  151. evs.pb({rects[i].r.x, ysr[rects[i].r.y], ysr[rects[i].l.y], rects[i].w, i, 1});
  152. }
  153. sort(all(evs), cmp);
  154. // for(auto i : evs) {
  155. // cout << i.bot << " ";
  156. // }
  157. // cout << '\n';
  158. vi mx(n), pr(n, -1);
  159. for(int i = 0; i < 2 * n; i++) {
  160. if(evs[i].t == -1) {
  161. pii tans = get(0, 0, MAXN, evs[i].top + 1, MAXN);
  162. mx[evs[i].pos] = tans.x;
  163. pr[evs[i].pos] = tans.y;
  164. }
  165. else {
  166. // cout << evs[i].bot << " " << evs[i].w << '\n';
  167. update(0, 0, MAXN, evs[i].bot, mx[evs[i].pos] + evs[i].w, evs[i].pos);
  168. }
  169. }
  170. int maxi, mxx = 0;
  171. for(int i = 0; i < upd.size(); i++) {
  172. if(upd[i] > mxx) {
  173. mxx = upd[i];
  174. maxi = i;
  175. }
  176. }
  177. // cout << upd[3].x << " " << upd[3].y << '\n';
  178. cout << mxx << '\n';
  179. vi anss;
  180. int cur = maxi;
  181. // cout << maxi + 1 << '\n';
  182. // for(auto i : pr) {
  183. // cout << i << " ";
  184. // }
  185. // cout << '\n';
  186. while(pr[cur] != -1) {
  187. anss.pb(cur);
  188. cur = pr[cur];
  189. }
  190. anss.pb(cur);
  191. reverse(all(anss));
  192. for(auto i : anss) {
  193. cout << i + 1 << " ";
  194. }
  195. // for(int i = 0; i < 10; i++) {
  196. // cout << upd[i] << " ";
  197. // }
  198. // for(int i = 0; i < 30; i++) {
  199. // cout << t[i] << " ";
  200. // }
  201. // for(auto i : mx) {
  202. // cout << i << " ";
  203. // }
  204. return 0;
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement