Submission #567780

# Submission time Handle Problem Language Result Execution time Memory
567780 2022-05-24T07:42:56 Z errorgorn Team Contest (JOI22_team) C++17
100 / 100
260 ms 17828 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define endl '\n'

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct node{
	const int BUF=150050;
	int arr[300100];
	
	node(){
		memset(arr,-1,sizeof(arr));
	}
	
	void update(int i,int j){
		i+=BUF;
		arr[i]=max(arr[i],j);
		while (i){
			i>>=1;
			arr[i]=max(arr[i<<1],arr[i<<1|1]);
		}
	}
	
	int query(int i,int j){
		i+=BUF,j+=BUF+1;
		int res=-1;
		
		while (i<j){
			if (i&1) res=max(res,arr[i++]);
			if (j&1) res=max(res,arr[--j]);
			i>>=1,j>>=1;
		}
		return res;
	}
} root1,root2;

int n;
int arr[150005][3];
vector<int> uni[3];

ii best={-1,-1};
void add(int i,int j){
	//cout<<"adding: "<<i<<" "<<j<<" "<<endl;
	root1.update(i,j);
	root2.update(j,i);
	
	int j2=root1.query(0,i-1);
	int i2=root2.query(0,j-1);
	
	if (j<j2) best=max(best,ii(i,j2));
	if (i<i2) best=max(best,ii(i2,j));
}

signed main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n;
	rep(x,0,n) rep(y,0,3) cin>>arr[x][y];
	
	rep(x,0,n) rep(y,0,3) uni[y].pub(arr[x][y]);
	rep(x,0,3) sort(all(uni[x]));
	rep(x,0,n) rep(y,0,3) arr[x][y]=lb(all(uni[y]),arr[x][y])-uni[y].begin();
	
	//rep(x,0,n){
		//rep(y,0,3) cout<<arr[x][y]<<" "; cout<<endl;
	//}
	
	vector<int> idx;
	rep(x,0,n) idx.pub(x);
	sort(all(idx),[](int i,int j){
		return arr[i][0]<arr[j][0];
	});
	
	int curr=0;
	int ans=-1;
	rep(x,0,n){
		while (arr[idx[curr]][0]<arr[idx[x]][0]){
			add(arr[idx[curr]][1],arr[idx[curr]][2]);
			curr++;
		}
		
		if (arr[idx[x]][1]<best.fi && arr[idx[x]][2]<best.se){
			ans=max(ans,uni[0][arr[idx[x]][0]]+uni[1][best.fi]+uni[2][best.se]);
		}
	}
	
	cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5032 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 4 ms 5028 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5032 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 4 ms 5028 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 6 ms 5332 KB Output is correct
27 Correct 6 ms 5292 KB Output is correct
28 Correct 6 ms 5332 KB Output is correct
29 Correct 6 ms 5332 KB Output is correct
30 Correct 5 ms 5176 KB Output is correct
31 Correct 8 ms 5252 KB Output is correct
32 Correct 5 ms 5300 KB Output is correct
33 Correct 5 ms 5344 KB Output is correct
34 Correct 5 ms 5296 KB Output is correct
35 Correct 3 ms 5040 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 6 ms 5300 KB Output is correct
38 Correct 8 ms 5216 KB Output is correct
39 Correct 5 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 75 ms 15076 KB Output is correct
12 Correct 49 ms 11196 KB Output is correct
13 Correct 54 ms 13056 KB Output is correct
14 Correct 75 ms 15884 KB Output is correct
15 Correct 55 ms 15512 KB Output is correct
16 Correct 50 ms 15732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 75 ms 15076 KB Output is correct
12 Correct 49 ms 11196 KB Output is correct
13 Correct 54 ms 13056 KB Output is correct
14 Correct 75 ms 15884 KB Output is correct
15 Correct 55 ms 15512 KB Output is correct
16 Correct 50 ms 15732 KB Output is correct
17 Correct 5 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 5172 KB Output is correct
22 Correct 118 ms 15968 KB Output is correct
23 Correct 93 ms 15708 KB Output is correct
24 Correct 79 ms 12264 KB Output is correct
25 Correct 138 ms 16264 KB Output is correct
26 Correct 65 ms 16104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 75 ms 15076 KB Output is correct
12 Correct 49 ms 11196 KB Output is correct
13 Correct 54 ms 13056 KB Output is correct
14 Correct 75 ms 15884 KB Output is correct
15 Correct 55 ms 15512 KB Output is correct
16 Correct 50 ms 15732 KB Output is correct
17 Correct 5 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 5172 KB Output is correct
22 Correct 118 ms 15968 KB Output is correct
23 Correct 93 ms 15708 KB Output is correct
24 Correct 79 ms 12264 KB Output is correct
25 Correct 138 ms 16264 KB Output is correct
26 Correct 65 ms 16104 KB Output is correct
27 Correct 3 ms 5028 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 2 ms 4948 KB Output is correct
30 Correct 3 ms 5028 KB Output is correct
31 Correct 6 ms 5204 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 168 ms 16120 KB Output is correct
35 Correct 160 ms 15448 KB Output is correct
36 Correct 177 ms 16188 KB Output is correct
37 Correct 152 ms 16752 KB Output is correct
38 Correct 73 ms 16188 KB Output is correct
39 Correct 39 ms 11396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 75 ms 15076 KB Output is correct
12 Correct 49 ms 11196 KB Output is correct
13 Correct 54 ms 13056 KB Output is correct
14 Correct 75 ms 15884 KB Output is correct
15 Correct 55 ms 15512 KB Output is correct
16 Correct 50 ms 15732 KB Output is correct
17 Correct 5 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 5172 KB Output is correct
22 Correct 118 ms 15968 KB Output is correct
23 Correct 93 ms 15708 KB Output is correct
24 Correct 79 ms 12264 KB Output is correct
25 Correct 138 ms 16264 KB Output is correct
26 Correct 65 ms 16104 KB Output is correct
27 Correct 3 ms 5028 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 2 ms 4948 KB Output is correct
30 Correct 3 ms 5028 KB Output is correct
31 Correct 6 ms 5204 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 168 ms 16120 KB Output is correct
35 Correct 160 ms 15448 KB Output is correct
36 Correct 177 ms 16188 KB Output is correct
37 Correct 152 ms 16752 KB Output is correct
38 Correct 73 ms 16188 KB Output is correct
39 Correct 39 ms 11396 KB Output is correct
40 Correct 6 ms 5332 KB Output is correct
41 Correct 6 ms 5332 KB Output is correct
42 Correct 7 ms 5308 KB Output is correct
43 Correct 7 ms 5296 KB Output is correct
44 Correct 211 ms 17160 KB Output is correct
45 Correct 187 ms 17144 KB Output is correct
46 Correct 187 ms 16560 KB Output is correct
47 Correct 198 ms 16932 KB Output is correct
48 Correct 94 ms 16832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5032 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 4 ms 5028 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 6 ms 5332 KB Output is correct
27 Correct 6 ms 5292 KB Output is correct
28 Correct 6 ms 5332 KB Output is correct
29 Correct 6 ms 5332 KB Output is correct
30 Correct 5 ms 5176 KB Output is correct
31 Correct 8 ms 5252 KB Output is correct
32 Correct 5 ms 5300 KB Output is correct
33 Correct 5 ms 5344 KB Output is correct
34 Correct 5 ms 5296 KB Output is correct
35 Correct 3 ms 5040 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 6 ms 5300 KB Output is correct
38 Correct 8 ms 5216 KB Output is correct
39 Correct 5 ms 5076 KB Output is correct
40 Correct 2 ms 4948 KB Output is correct
41 Correct 2 ms 4948 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 2 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 2 ms 4948 KB Output is correct
47 Correct 2 ms 4948 KB Output is correct
48 Correct 2 ms 4948 KB Output is correct
49 Correct 2 ms 4948 KB Output is correct
50 Correct 75 ms 15076 KB Output is correct
51 Correct 49 ms 11196 KB Output is correct
52 Correct 54 ms 13056 KB Output is correct
53 Correct 75 ms 15884 KB Output is correct
54 Correct 55 ms 15512 KB Output is correct
55 Correct 50 ms 15732 KB Output is correct
56 Correct 5 ms 4948 KB Output is correct
57 Correct 3 ms 4948 KB Output is correct
58 Correct 3 ms 4948 KB Output is correct
59 Correct 3 ms 4948 KB Output is correct
60 Correct 4 ms 5172 KB Output is correct
61 Correct 118 ms 15968 KB Output is correct
62 Correct 93 ms 15708 KB Output is correct
63 Correct 79 ms 12264 KB Output is correct
64 Correct 138 ms 16264 KB Output is correct
65 Correct 65 ms 16104 KB Output is correct
66 Correct 3 ms 5028 KB Output is correct
67 Correct 2 ms 4948 KB Output is correct
68 Correct 2 ms 4948 KB Output is correct
69 Correct 3 ms 5028 KB Output is correct
70 Correct 6 ms 5204 KB Output is correct
71 Correct 3 ms 5076 KB Output is correct
72 Correct 3 ms 5076 KB Output is correct
73 Correct 168 ms 16120 KB Output is correct
74 Correct 160 ms 15448 KB Output is correct
75 Correct 177 ms 16188 KB Output is correct
76 Correct 152 ms 16752 KB Output is correct
77 Correct 73 ms 16188 KB Output is correct
78 Correct 39 ms 11396 KB Output is correct
79 Correct 6 ms 5332 KB Output is correct
80 Correct 6 ms 5332 KB Output is correct
81 Correct 7 ms 5308 KB Output is correct
82 Correct 7 ms 5296 KB Output is correct
83 Correct 211 ms 17160 KB Output is correct
84 Correct 187 ms 17144 KB Output is correct
85 Correct 187 ms 16560 KB Output is correct
86 Correct 198 ms 16932 KB Output is correct
87 Correct 94 ms 16832 KB Output is correct
88 Correct 227 ms 17748 KB Output is correct
89 Correct 233 ms 17152 KB Output is correct
90 Correct 260 ms 17828 KB Output is correct
91 Correct 213 ms 16572 KB Output is correct
92 Correct 215 ms 16628 KB Output is correct
93 Correct 243 ms 17520 KB Output is correct
94 Correct 227 ms 17488 KB Output is correct
95 Correct 96 ms 17824 KB Output is correct
96 Correct 192 ms 17828 KB Output is correct
97 Correct 83 ms 17528 KB Output is correct
98 Correct 111 ms 17392 KB Output is correct
99 Correct 141 ms 17348 KB Output is correct