Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- --┬-- | | --┬-- | |
- | |\ | | | |
- | | \ | | -----> | |
- | | \ | | | |
- | | \ | | | |
- --┴-- | \| | └---- └----
- */
- #define pragma
- #ifdef pragma
- #pragma GCC optimize("Ofast")
- #pragma GCC optimize("no-stack-protector")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #pragma GCC optimize("unroll-loops")
- #endif // pragma
- #include<bits/stdc++.h>
- #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
- using namespace std;
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef pair<int,int> pii;
- typedef long double ld;
- typedef vector<vi> matrix;
- const int INF = 1e18 + 7;
- const int MAXN = 1e6 + 7;
- const ld EPS = 1e-9;
- const ld PI = atan2(0, -1);
- void seriy() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- // cout << fixed << setprecision(6);
- #if 1
- freopen("input", "r", stdin);
- freopen("output", "w", stdout);
- #endif
- }
- struct pt {
- int x, y;
- };
- struct rect {
- pt l, r;
- int w;
- };
- struct event {
- int x, top, bot, w, pos, t;
- };
- istream& operator>>(istream& is, pt& p) {
- is >> p.x >> p.y;
- return is;
- }
- ostream& operator<<(ostream& os, pt& p) {
- os << p.x << " " << p.y;
- return os;
- }
- vector<pii> t(4 * MAXN, {0, -1});
- vector<int> upd(MAXN, -1);
- pii get(int v, int tl, int tr, int l, int r) {
- if(tl > r || tr < l) {
- return {-INF, -1};
- }
- if(tl >= l && tr <= r) {
- return t[v];
- }
- int tm = (tl + tr) >> 1;
- pii x = get(v * 2 + 1, tl, tm, l, r);
- pii y = get(v * 2 + 2, tm + 1, tr, l, r);
- if(x.x > y.x) {
- return x;
- }
- else {
- return y;
- }
- // return max(x, y);
- }
- void update(int v, int tl, int tr, int x, int val, int num) {
- if(x > tr || x < tl) {
- return;
- }
- if(tl == tr) {
- if(val > t[v].x) {
- t[v] = {val, num};
- }
- upd[num] = t[v].x;
- // upd[tl].y = num;
- return;
- }
- int tm = (tl + tr) >> 1;
- update(v * 2 + 1, tl, tm, x, val, num);
- update(v * 2 + 2, tm + 1, tr, x, val, num);
- t[v] = ((t[v * 2 + 1].x > t[v * 2 + 2].x) ? t[v * 2 + 1] : t[v * 2 + 2]);
- }
- bool cmp(event a, event b) {
- return a.x < b.x || a.x == b.x && a.t < b.t;
- }
- signed main() {
- seriy();
- int n;
- cin >> n;
- vector<rect> rects(n);
- map<int, int> ys;
- map<int, int> xs;
- map<int, int> ysr;
- map<int, int> xsr;
- vi yy;
- int num = 1, num1 = 1;
- for(int i = 0; i < n; i++) {
- cin >> rects[i].l >> rects[i].r >> rects[i].w;
- rects[i].l.x += 1e9;
- rects[i].l.y += 1e9;
- rects[i].r.x += 1e9;
- rects[i].r.y += 1e9;
- yy.pb(rects[i].l.y);
- yy.pb(rects[i].r.y);
- }
- sort(all(yy));
- for(int i = 0; i < yy.size(); i++) {
- if(ysr[yy[i]] == 0) {
- ys[num] = yy[i];
- ysr[yy[i]] = num;
- num++;
- }
- }
- vector<event> evs;
- for(int i = 0; i < n; i++) {
- evs.pb({rects[i].l.x, ysr[rects[i].r.y], ysr[rects[i].l.y], rects[i].w, i, -1});
- evs.pb({rects[i].r.x, ysr[rects[i].r.y], ysr[rects[i].l.y], rects[i].w, i, 1});
- }
- sort(all(evs), cmp);
- // for(auto i : evs) {
- // cout << i.bot << " ";
- // }
- // cout << '\n';
- vi mx(n), pr(n, -1);
- for(int i = 0; i < 2 * n; i++) {
- if(evs[i].t == -1) {
- pii tans = get(0, 0, MAXN, evs[i].top + 1, MAXN);
- mx[evs[i].pos] = tans.x;
- pr[evs[i].pos] = tans.y;
- }
- else {
- // cout << evs[i].bot << " " << evs[i].w << '\n';
- update(0, 0, MAXN, evs[i].bot, mx[evs[i].pos] + evs[i].w, evs[i].pos);
- }
- }
- int maxi, mxx = 0;
- for(int i = 0; i < upd.size(); i++) {
- if(upd[i] > mxx) {
- mxx = upd[i];
- maxi = i;
- }
- }
- // cout << upd[3].x << " " << upd[3].y << '\n';
- cout << mxx << '\n';
- vi anss;
- int cur = maxi;
- // cout << maxi + 1 << '\n';
- // for(auto i : pr) {
- // cout << i << " ";
- // }
- // cout << '\n';
- while(pr[cur] != -1) {
- anss.pb(cur);
- cur = pr[cur];
- }
- anss.pb(cur);
- reverse(all(anss));
- for(auto i : anss) {
- cout << i + 1 << " ";
- }
- // for(int i = 0; i < 10; i++) {
- // cout << upd[i] << " ";
- // }
- // for(int i = 0; i < 30; i++) {
- // cout << t[i] << " ";
- // }
- // for(auto i : mx) {
- // cout << i << " ";
- // }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement