Submission #972538

# Submission time Handle Problem Language Result Execution time Memory
972538 2024-04-30T14:27:50 Z happy_node Team Contest (JOI22_team) C++17
100 / 100
778 ms 65716 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX=2e5+5;
int N;
int X[MX],Y[MX],Z[MX],mn[MX];

vector<pair<int,int>> ops[MX];

priority_queue<int, vector<int>, greater<int>> pend[MX]; 

struct segtree {
    	pair<int,int> t[4 * MX];
 
     	void update(int v, int l, int r, int pos, int val) {
           	if(l > pos || r < pos) return;
           	if(l == r) {
                 	t[v] = make_pair(val, pos);
                 	return;
           	}
           	int mid = (l + r) >> 1;
           	update(v * 2 + 0, l, mid + 0, pos, val);
           	update(v * 2 + 1, mid + 1, r, pos, val);
           	t[v] = min(t[v * 2 + 0], t[v * 2 + 1]);
     	}
 
     	pair<int,int> query(int v, int l, int r, int ql, int qr) {
           	if(ql > r || qr < l) return make_pair(1e8, 1e8);
           	if(ql <= l && qr >= r) return t[v];
           	int mid = (l + r) >> 1;
           	return min(query(v * 2 + 0, l, mid + 0, ql, qr), query(v * 2 + 1, mid + 1, r, ql, qr));
      	}

      	void prep() {
      		for(int i=0;i<4*MX;i++) t[i]=make_pair(1e8,i);
      	}
} st, tt;

priority_queue<pair<int,int>> pts;

int rx[MX], ry[MX], rz[MX];

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);

	st.prep();
	tt.prep();

	cin>>N;

	map<int,int> ix,iy,iz;
	for(int i=0;i<N;i++) {
		cin>>X[i]>>Y[i]>>Z[i];
		ix[X[i]]=0;
		iy[Y[i]]=0;
		iz[Z[i]]=0;
	}

	int p=0;
	for(auto &[x,y]:ix) y=p++, rx[y]=x;
	p=0;
	for(auto &[x,y]:iy) y=p++, ry[y]=x;
	p=0;
	for(auto &[x,y]:iz) y=p++, rz[y]=x;

	for(int i=0;i<N;i++) {
		ops[iz[Z[i]]].push_back({ix[X[i]],iy[Y[i]]});
		pend[i].push(1e8);
		mn[i]=1e8;
	} 	

	int ans=-1;

	for(int z=0;z<N;z++) {
		// evaluate
		for(auto [x,y]:ops[z]) {
			if(pts.empty()) continue;
			auto [yy,xx]=pts.top();

			// wanna get rightmost x
			int l=xx+1,r=N,res=-1;
			while(l<=r) {
				int mid=(l+r)/2;
				if(tt.query(1,0,N,mid,N).first<yy) {
					res=mid,l=mid+1;
				} else {
					r=mid-1;
				}
			}

			if(res<=x||yy<=y) continue;

			ans=max(ans,rz[z]+ry[yy]+rx[res]);
		}	

		// insert
		for(auto [x,y]:ops[z]) {
			if(tt.query(1,0,N,x+1,N).first>=y) {
				pend[y].push(x);
				st.update(1,0,N,y,pend[y].top());
			} else {
				pts.push({y,x});
			}
			mn[x]=min(mn[x],y);
			tt.update(1,0,N,x,mn[x]);
		}

		for(auto [x,y]:ops[z]) {
			while(true) {
				auto [v,k]=st.query(1,0,N,y+1,N);
				if(v<x) {
					pts.push({k,v});
					pend[k].pop();
					st.update(1,0,N,k,pend[k].top());
				} else {
					break;
				}
			}
		}
	}

	cout<<ans<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29016 KB Output is correct
2 Correct 6 ms 29016 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 7 ms 29020 KB Output is correct
5 Correct 6 ms 29020 KB Output is correct
6 Correct 6 ms 29020 KB Output is correct
7 Correct 6 ms 29172 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 6 ms 29020 KB Output is correct
10 Correct 6 ms 29020 KB Output is correct
11 Correct 7 ms 29020 KB Output is correct
12 Correct 6 ms 29020 KB Output is correct
13 Correct 6 ms 29020 KB Output is correct
14 Correct 6 ms 29020 KB Output is correct
15 Correct 7 ms 29020 KB Output is correct
16 Correct 7 ms 29240 KB Output is correct
17 Correct 6 ms 29164 KB Output is correct
18 Correct 6 ms 29020 KB Output is correct
19 Correct 6 ms 29112 KB Output is correct
20 Correct 6 ms 29020 KB Output is correct
21 Correct 6 ms 29168 KB Output is correct
22 Correct 8 ms 29164 KB Output is correct
23 Correct 6 ms 29020 KB Output is correct
24 Correct 7 ms 29020 KB Output is correct
25 Correct 6 ms 29020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29016 KB Output is correct
2 Correct 6 ms 29016 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 7 ms 29020 KB Output is correct
5 Correct 6 ms 29020 KB Output is correct
6 Correct 6 ms 29020 KB Output is correct
7 Correct 6 ms 29172 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 6 ms 29020 KB Output is correct
10 Correct 6 ms 29020 KB Output is correct
11 Correct 7 ms 29020 KB Output is correct
12 Correct 6 ms 29020 KB Output is correct
13 Correct 6 ms 29020 KB Output is correct
14 Correct 6 ms 29020 KB Output is correct
15 Correct 7 ms 29020 KB Output is correct
16 Correct 7 ms 29240 KB Output is correct
17 Correct 6 ms 29164 KB Output is correct
18 Correct 6 ms 29020 KB Output is correct
19 Correct 6 ms 29112 KB Output is correct
20 Correct 6 ms 29020 KB Output is correct
21 Correct 6 ms 29168 KB Output is correct
22 Correct 8 ms 29164 KB Output is correct
23 Correct 6 ms 29020 KB Output is correct
24 Correct 7 ms 29020 KB Output is correct
25 Correct 6 ms 29020 KB Output is correct
26 Correct 14 ms 30040 KB Output is correct
27 Correct 14 ms 29820 KB Output is correct
28 Correct 14 ms 29788 KB Output is correct
29 Correct 14 ms 29764 KB Output is correct
30 Correct 11 ms 29532 KB Output is correct
31 Correct 13 ms 29532 KB Output is correct
32 Correct 11 ms 29528 KB Output is correct
33 Correct 8 ms 29532 KB Output is correct
34 Correct 14 ms 30300 KB Output is correct
35 Correct 6 ms 29272 KB Output is correct
36 Correct 7 ms 29272 KB Output is correct
37 Correct 9 ms 29532 KB Output is correct
38 Correct 12 ms 29484 KB Output is correct
39 Correct 8 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29016 KB Output is correct
2 Correct 6 ms 29020 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 7 ms 29016 KB Output is correct
5 Correct 6 ms 29020 KB Output is correct
6 Correct 7 ms 29016 KB Output is correct
7 Correct 6 ms 29020 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 6 ms 29104 KB Output is correct
10 Correct 6 ms 29020 KB Output is correct
11 Correct 216 ms 37172 KB Output is correct
12 Correct 109 ms 35168 KB Output is correct
13 Correct 73 ms 35460 KB Output is correct
14 Correct 117 ms 37828 KB Output is correct
15 Correct 77 ms 37300 KB Output is correct
16 Correct 77 ms 37308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29016 KB Output is correct
2 Correct 6 ms 29020 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 7 ms 29016 KB Output is correct
5 Correct 6 ms 29020 KB Output is correct
6 Correct 7 ms 29016 KB Output is correct
7 Correct 6 ms 29020 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 6 ms 29104 KB Output is correct
10 Correct 6 ms 29020 KB Output is correct
11 Correct 216 ms 37172 KB Output is correct
12 Correct 109 ms 35168 KB Output is correct
13 Correct 73 ms 35460 KB Output is correct
14 Correct 117 ms 37828 KB Output is correct
15 Correct 77 ms 37300 KB Output is correct
16 Correct 77 ms 37308 KB Output is correct
17 Correct 6 ms 29016 KB Output is correct
18 Correct 6 ms 29020 KB Output is correct
19 Correct 6 ms 29020 KB Output is correct
20 Correct 11 ms 29020 KB Output is correct
21 Correct 9 ms 29108 KB Output is correct
22 Correct 310 ms 38280 KB Output is correct
23 Correct 251 ms 36876 KB Output is correct
24 Correct 179 ms 35528 KB Output is correct
25 Correct 228 ms 38964 KB Output is correct
26 Correct 84 ms 37344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29016 KB Output is correct
2 Correct 6 ms 29020 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 7 ms 29016 KB Output is correct
5 Correct 6 ms 29020 KB Output is correct
6 Correct 7 ms 29016 KB Output is correct
7 Correct 6 ms 29020 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 6 ms 29104 KB Output is correct
10 Correct 6 ms 29020 KB Output is correct
11 Correct 216 ms 37172 KB Output is correct
12 Correct 109 ms 35168 KB Output is correct
13 Correct 73 ms 35460 KB Output is correct
14 Correct 117 ms 37828 KB Output is correct
15 Correct 77 ms 37300 KB Output is correct
16 Correct 77 ms 37308 KB Output is correct
17 Correct 6 ms 29016 KB Output is correct
18 Correct 6 ms 29020 KB Output is correct
19 Correct 6 ms 29020 KB Output is correct
20 Correct 11 ms 29020 KB Output is correct
21 Correct 9 ms 29108 KB Output is correct
22 Correct 310 ms 38280 KB Output is correct
23 Correct 251 ms 36876 KB Output is correct
24 Correct 179 ms 35528 KB Output is correct
25 Correct 228 ms 38964 KB Output is correct
26 Correct 84 ms 37344 KB Output is correct
27 Correct 6 ms 29020 KB Output is correct
28 Correct 8 ms 29020 KB Output is correct
29 Correct 7 ms 29020 KB Output is correct
30 Correct 6 ms 29020 KB Output is correct
31 Correct 13 ms 29276 KB Output is correct
32 Correct 8 ms 25076 KB Output is correct
33 Correct 7 ms 29272 KB Output is correct
34 Correct 285 ms 38676 KB Output is correct
35 Correct 275 ms 38840 KB Output is correct
36 Correct 292 ms 39200 KB Output is correct
37 Correct 258 ms 39544 KB Output is correct
38 Correct 95 ms 38124 KB Output is correct
39 Correct 60 ms 34808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29016 KB Output is correct
2 Correct 6 ms 29020 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 7 ms 29016 KB Output is correct
5 Correct 6 ms 29020 KB Output is correct
6 Correct 7 ms 29016 KB Output is correct
7 Correct 6 ms 29020 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 6 ms 29104 KB Output is correct
10 Correct 6 ms 29020 KB Output is correct
11 Correct 216 ms 37172 KB Output is correct
12 Correct 109 ms 35168 KB Output is correct
13 Correct 73 ms 35460 KB Output is correct
14 Correct 117 ms 37828 KB Output is correct
15 Correct 77 ms 37300 KB Output is correct
16 Correct 77 ms 37308 KB Output is correct
17 Correct 6 ms 29016 KB Output is correct
18 Correct 6 ms 29020 KB Output is correct
19 Correct 6 ms 29020 KB Output is correct
20 Correct 11 ms 29020 KB Output is correct
21 Correct 9 ms 29108 KB Output is correct
22 Correct 310 ms 38280 KB Output is correct
23 Correct 251 ms 36876 KB Output is correct
24 Correct 179 ms 35528 KB Output is correct
25 Correct 228 ms 38964 KB Output is correct
26 Correct 84 ms 37344 KB Output is correct
27 Correct 6 ms 29020 KB Output is correct
28 Correct 8 ms 29020 KB Output is correct
29 Correct 7 ms 29020 KB Output is correct
30 Correct 6 ms 29020 KB Output is correct
31 Correct 13 ms 29276 KB Output is correct
32 Correct 8 ms 25076 KB Output is correct
33 Correct 7 ms 29272 KB Output is correct
34 Correct 285 ms 38676 KB Output is correct
35 Correct 275 ms 38840 KB Output is correct
36 Correct 292 ms 39200 KB Output is correct
37 Correct 258 ms 39544 KB Output is correct
38 Correct 95 ms 38124 KB Output is correct
39 Correct 60 ms 34808 KB Output is correct
40 Correct 14 ms 29456 KB Output is correct
41 Correct 14 ms 29528 KB Output is correct
42 Correct 10 ms 29532 KB Output is correct
43 Correct 23 ms 28308 KB Output is correct
44 Correct 385 ms 40636 KB Output is correct
45 Correct 378 ms 40660 KB Output is correct
46 Correct 388 ms 40628 KB Output is correct
47 Correct 352 ms 40672 KB Output is correct
48 Correct 114 ms 38852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29016 KB Output is correct
2 Correct 6 ms 29016 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 7 ms 29020 KB Output is correct
5 Correct 6 ms 29020 KB Output is correct
6 Correct 6 ms 29020 KB Output is correct
7 Correct 6 ms 29172 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 6 ms 29020 KB Output is correct
10 Correct 6 ms 29020 KB Output is correct
11 Correct 7 ms 29020 KB Output is correct
12 Correct 6 ms 29020 KB Output is correct
13 Correct 6 ms 29020 KB Output is correct
14 Correct 6 ms 29020 KB Output is correct
15 Correct 7 ms 29020 KB Output is correct
16 Correct 7 ms 29240 KB Output is correct
17 Correct 6 ms 29164 KB Output is correct
18 Correct 6 ms 29020 KB Output is correct
19 Correct 6 ms 29112 KB Output is correct
20 Correct 6 ms 29020 KB Output is correct
21 Correct 6 ms 29168 KB Output is correct
22 Correct 8 ms 29164 KB Output is correct
23 Correct 6 ms 29020 KB Output is correct
24 Correct 7 ms 29020 KB Output is correct
25 Correct 6 ms 29020 KB Output is correct
26 Correct 14 ms 30040 KB Output is correct
27 Correct 14 ms 29820 KB Output is correct
28 Correct 14 ms 29788 KB Output is correct
29 Correct 14 ms 29764 KB Output is correct
30 Correct 11 ms 29532 KB Output is correct
31 Correct 13 ms 29532 KB Output is correct
32 Correct 11 ms 29528 KB Output is correct
33 Correct 8 ms 29532 KB Output is correct
34 Correct 14 ms 30300 KB Output is correct
35 Correct 6 ms 29272 KB Output is correct
36 Correct 7 ms 29272 KB Output is correct
37 Correct 9 ms 29532 KB Output is correct
38 Correct 12 ms 29484 KB Output is correct
39 Correct 8 ms 29276 KB Output is correct
40 Correct 6 ms 29016 KB Output is correct
41 Correct 6 ms 29020 KB Output is correct
42 Correct 6 ms 29020 KB Output is correct
43 Correct 7 ms 29016 KB Output is correct
44 Correct 6 ms 29020 KB Output is correct
45 Correct 7 ms 29016 KB Output is correct
46 Correct 6 ms 29020 KB Output is correct
47 Correct 6 ms 29020 KB Output is correct
48 Correct 6 ms 29104 KB Output is correct
49 Correct 6 ms 29020 KB Output is correct
50 Correct 216 ms 37172 KB Output is correct
51 Correct 109 ms 35168 KB Output is correct
52 Correct 73 ms 35460 KB Output is correct
53 Correct 117 ms 37828 KB Output is correct
54 Correct 77 ms 37300 KB Output is correct
55 Correct 77 ms 37308 KB Output is correct
56 Correct 6 ms 29016 KB Output is correct
57 Correct 6 ms 29020 KB Output is correct
58 Correct 6 ms 29020 KB Output is correct
59 Correct 11 ms 29020 KB Output is correct
60 Correct 9 ms 29108 KB Output is correct
61 Correct 310 ms 38280 KB Output is correct
62 Correct 251 ms 36876 KB Output is correct
63 Correct 179 ms 35528 KB Output is correct
64 Correct 228 ms 38964 KB Output is correct
65 Correct 84 ms 37344 KB Output is correct
66 Correct 6 ms 29020 KB Output is correct
67 Correct 8 ms 29020 KB Output is correct
68 Correct 7 ms 29020 KB Output is correct
69 Correct 6 ms 29020 KB Output is correct
70 Correct 13 ms 29276 KB Output is correct
71 Correct 8 ms 25076 KB Output is correct
72 Correct 7 ms 29272 KB Output is correct
73 Correct 285 ms 38676 KB Output is correct
74 Correct 275 ms 38840 KB Output is correct
75 Correct 292 ms 39200 KB Output is correct
76 Correct 258 ms 39544 KB Output is correct
77 Correct 95 ms 38124 KB Output is correct
78 Correct 60 ms 34808 KB Output is correct
79 Correct 14 ms 29456 KB Output is correct
80 Correct 14 ms 29528 KB Output is correct
81 Correct 10 ms 29532 KB Output is correct
82 Correct 23 ms 28308 KB Output is correct
83 Correct 385 ms 40636 KB Output is correct
84 Correct 378 ms 40660 KB Output is correct
85 Correct 388 ms 40628 KB Output is correct
86 Correct 352 ms 40672 KB Output is correct
87 Correct 114 ms 38852 KB Output is correct
88 Correct 778 ms 65716 KB Output is correct
89 Correct 699 ms 54724 KB Output is correct
90 Correct 667 ms 56216 KB Output is correct
91 Correct 633 ms 52172 KB Output is correct
92 Correct 488 ms 44576 KB Output is correct
93 Correct 711 ms 54332 KB Output is correct
94 Correct 534 ms 49076 KB Output is correct
95 Correct 185 ms 46316 KB Output is correct
96 Correct 503 ms 63776 KB Output is correct
97 Correct 89 ms 40412 KB Output is correct
98 Correct 149 ms 46544 KB Output is correct
99 Correct 316 ms 46420 KB Output is correct