Submission #618997

# Submission time Handle Problem Language Result Execution time Memory
618997 2022-08-02T08:51:25 Z CSQ31 Team Contest (JOI22_team) C++17
100 / 100
1350 ms 46452 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
typedef pair<int,int> pii;
typedef long long int ll;
const int MAXN = 5e5;
array<ll,3>pts1[MAXN],pts2[MAXN];
vector<array<ll,3>>a;
vector<int>crd[3];
//i have rectangle queries but i cant do it offline?
//i can but its double log on 2s
//ok try n^2 first
int sz0,sz1,sz2;
struct seg{
	vector<int>t;
	int n;
	seg(){}
	seg(int _n){
		n = _n;
		t.assign(4*n+1,-2e9);
	}
	void upd(int v,int pos,int l,int r,int val){
		if(l==r){
			t[v] = max(t[v],val);
			return;
		}
		int tm = (l+r)/2;
		if(pos<=tm)upd(2*v,pos,l,tm,val);
		else upd(2*v+1,pos,tm+1,r,val);
		t[v] = max(t[2*v],t[2*v+1]);
	}
	void upd2(int v,int pos,int l,int r,int val){
		if(l==r){
			t[v] = val;
			return;
		}
		int tm = (l+r)/2;
		if(pos<=tm)upd2(2*v,pos,l,tm,val);
		else upd2(2*v+1,pos,tm+1,r,val);
		t[v] = max(t[2*v],t[2*v+1]);
	}
	int query(int v,int l,int r,int tl,int tr){
		if(l>r)return -2e9;
		if(l==tl && r==tr)return t[v];
		int tm = (tl+tr)/2;
		if(r<=tm)return query(2*v,l,r,tl,tm);
		else if(l>tm)return query(2*v+1,l,r,tm+1,tr);
		else return max(query(2*v,l,tm,tl,tm),query(2*v+1,tm+1,r,tm+1,tr));
	}
}amx(2e5);
ll ans = -1;
vector<int>pts[MAXN];
 
void solve(int l,int r){
	if(l==r){
		return;
	}
	//all same a
	int mid = (l+r)/2;
	solve(l,mid);
	solve(mid+1,r);
	vector<pii>que;
	vector<array<ll,3>>add;
	for(int i=l;i<=mid;i++){
		for(int x:pts[i]){
			if(pts1[x][0] != -2e9){
				add.pb({pts1[x][1],pts1[x][2],pts1[x][0]});
			}
			if(pts2[x][0] != -2e9){
				add.pb({pts2[x][1],pts2[x][2],pts2[x][0]});
			}
		}
	}
	for(int i=mid+1;i<=r;i++){
		for(int x:pts[i])que.push_back({a[x][1],x});
	}
	/*
	for(auto x:add){
		for(auto y:que){
			int id = y.se;
			if(y.fi  < x[0] && a[id][2] < x[1]){
				ans = max(ans,crd[0][a[id][0]] + x[2]);
				
			}
			
		}	
	}
	* */
	//seg amx(sz2);
	sort(all(add),greater<array<ll,3>>());
	sort(all(que),greater<pii>());
	int ptr = -1;
	for(pii qq : que){
		while(ptr+1 < sz(add) && add[ptr+1][0] > qq.fi){ //add still has bigger b
			ptr++;
			array<ll,3>v = add[ptr];
			amx.upd(1,v[1],0,sz2-1,v[2]);
		} 
		int id = qq.se;
		if(a[id][2]+1 < sz2){
			ll res = amx.query(1,a[id][2]+1,sz2-1,0,sz2-1); //we need a bigger ccout<<"query"<<'\n';
			ans = max(ans , crd[0][a[id][0]] + res);
		}
	}
	for(auto x:add)amx.upd2(1,x[1],0,sz2-1,-2e9);
}
int main()
{
	owo
	int n;
	cin>>n;
	a.resize(n);
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
			crd[j].pb(a[i][j]);
		}
	}
	sort(all(a),[&](array<ll,3>i,array<ll,3>j){return j[0] > i[0];});
	for(int j=0;j<3;j++){
		sort(all(crd[j]));
		crd[j].resize(unique(all(crd[j])) - crd[j].begin());
	}
	//cout<<"sorted"<<'\n';
	//for(int i=0;i<n;i++)cout<<a[i][0]<<" "<<a[i][1]<<" "<<a[i][2]<<'\n';
	sz0 = sz(crd[0]);
	sz1 = sz(crd[1]);
	sz2 = sz(crd[2]);
	seg bmx(sz1),cmx(sz2);
	//cout<<"points"<<'\n';
	for(int i=0;i<n;i++){
		pts1[i][0] = pts2[i][0] = -2e9;
		pts1[i][1] = a[i][1]; //i has bigger b
		pts2[i][2] = a[i][2]; //i has bigger c
		int s1 = lower_bound(all(crd[1]),a[i][1]) - crd[1].begin();
		int s2 = lower_bound(all(crd[2]),a[i][2]) - crd[2].begin();
		if(s1>0)pts1[i][2] = bmx.query(1,0,s1-1,0,sz1-1); //want the max of c among smaller bs
		if(s2>0)pts2[i][1] = cmx.query(1,0,s2-1,0,sz2-1); //want the max of b among smaller cs
		if(pts1[i][2] > a[i][2])pts1[i][0] = pts1[i][1] + pts1[i][2]; 
		if(pts2[i][1] > a[i][1])pts2[i][0] = pts2[i][1] + pts2[i][2];
		bmx.upd(1,s1,0,sz1-1,a[i][2]);
		cmx.upd(1,s2,0,sz2-1,a[i][1]);
		
		if(pts1[i][0] != -2e9){
			pts1[i][1] = lower_bound(all(crd[1]),pts1[i][1]) - crd[1].begin();
			pts1[i][2] = lower_bound(all(crd[2]),pts1[i][2]) - crd[2].begin();
		}
		if(pts2[i][0] != -2e9){
			pts2[i][1] = lower_bound(all(crd[1]),pts2[i][1]) - crd[1].begin();
			pts2[i][2] = lower_bound(all(crd[2]),pts2[i][2]) - crd[2].begin();
		}
		//this is correct
	}
	for(int i=0;i<n;i++){
		a[i][0] = lower_bound(all(crd[0]),a[i][0]) - crd[0].begin();
		a[i][1] = lower_bound(all(crd[1]),a[i][1]) - crd[1].begin();
		a[i][2] = lower_bound(all(crd[2]),a[i][2]) - crd[2].begin();
		pts[a[i][0]].pb(i);
	}
	/*
	for(int i=0;i<n;){
		int k = i;
		while(k+1<n && a[k][0] == a[k+1][0])k++;
		for(int x=i;x<=k;x++){
			for(int j=0;j<x;j++){
				if(a[x][0] == a[j][0])break;
				if(pts1[j][1] > a[x][1] && pts1[j][2] >a[x][2])ans = max(ans,crd[0][a[x][0]] + pts1[j][0]);
				if(pts2[j][1] > a[x][1] && pts2[j][2] >a[x][2])ans = max(ans,crd[0][a[x][0]] + pts2[j][0]);
			}
		}
		i = k+1;
	}*/
	//amx = seg(sz2);
	solve(0,sz0-1);
	cout<<ans;
	
	
	
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15188 KB Output is correct
2 Correct 8 ms 15188 KB Output is correct
3 Correct 7 ms 15188 KB Output is correct
4 Correct 8 ms 15188 KB Output is correct
5 Correct 8 ms 15188 KB Output is correct
6 Correct 9 ms 15188 KB Output is correct
7 Correct 8 ms 15188 KB Output is correct
8 Correct 8 ms 15188 KB Output is correct
9 Correct 8 ms 15188 KB Output is correct
10 Correct 8 ms 15152 KB Output is correct
11 Correct 7 ms 15092 KB Output is correct
12 Correct 8 ms 15188 KB Output is correct
13 Correct 7 ms 15188 KB Output is correct
14 Correct 8 ms 15188 KB Output is correct
15 Correct 8 ms 15188 KB Output is correct
16 Correct 8 ms 15208 KB Output is correct
17 Correct 8 ms 15216 KB Output is correct
18 Correct 8 ms 15188 KB Output is correct
19 Correct 9 ms 15188 KB Output is correct
20 Correct 8 ms 15188 KB Output is correct
21 Correct 10 ms 15188 KB Output is correct
22 Correct 8 ms 15188 KB Output is correct
23 Correct 8 ms 15188 KB Output is correct
24 Correct 9 ms 15188 KB Output is correct
25 Correct 10 ms 15188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15188 KB Output is correct
2 Correct 8 ms 15188 KB Output is correct
3 Correct 7 ms 15188 KB Output is correct
4 Correct 8 ms 15188 KB Output is correct
5 Correct 8 ms 15188 KB Output is correct
6 Correct 9 ms 15188 KB Output is correct
7 Correct 8 ms 15188 KB Output is correct
8 Correct 8 ms 15188 KB Output is correct
9 Correct 8 ms 15188 KB Output is correct
10 Correct 8 ms 15152 KB Output is correct
11 Correct 7 ms 15092 KB Output is correct
12 Correct 8 ms 15188 KB Output is correct
13 Correct 7 ms 15188 KB Output is correct
14 Correct 8 ms 15188 KB Output is correct
15 Correct 8 ms 15188 KB Output is correct
16 Correct 8 ms 15208 KB Output is correct
17 Correct 8 ms 15216 KB Output is correct
18 Correct 8 ms 15188 KB Output is correct
19 Correct 9 ms 15188 KB Output is correct
20 Correct 8 ms 15188 KB Output is correct
21 Correct 10 ms 15188 KB Output is correct
22 Correct 8 ms 15188 KB Output is correct
23 Correct 8 ms 15188 KB Output is correct
24 Correct 9 ms 15188 KB Output is correct
25 Correct 10 ms 15188 KB Output is correct
26 Correct 26 ms 15960 KB Output is correct
27 Correct 23 ms 15892 KB Output is correct
28 Correct 21 ms 15812 KB Output is correct
29 Correct 17 ms 15676 KB Output is correct
30 Correct 16 ms 15564 KB Output is correct
31 Correct 21 ms 15912 KB Output is correct
32 Correct 15 ms 15600 KB Output is correct
33 Correct 13 ms 15572 KB Output is correct
34 Correct 13 ms 15836 KB Output is correct
35 Correct 8 ms 15316 KB Output is correct
36 Correct 9 ms 15248 KB Output is correct
37 Correct 12 ms 15596 KB Output is correct
38 Correct 12 ms 15572 KB Output is correct
39 Correct 10 ms 15444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15188 KB Output is correct
2 Correct 10 ms 15144 KB Output is correct
3 Correct 9 ms 15160 KB Output is correct
4 Correct 8 ms 15092 KB Output is correct
5 Correct 8 ms 15188 KB Output is correct
6 Correct 7 ms 15156 KB Output is correct
7 Correct 7 ms 15156 KB Output is correct
8 Correct 9 ms 15188 KB Output is correct
9 Correct 8 ms 15188 KB Output is correct
10 Correct 10 ms 15188 KB Output is correct
11 Correct 130 ms 34036 KB Output is correct
12 Correct 66 ms 26116 KB Output is correct
13 Correct 50 ms 26864 KB Output is correct
14 Correct 90 ms 31112 KB Output is correct
15 Correct 71 ms 29976 KB Output is correct
16 Correct 65 ms 29156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15188 KB Output is correct
2 Correct 10 ms 15144 KB Output is correct
3 Correct 9 ms 15160 KB Output is correct
4 Correct 8 ms 15092 KB Output is correct
5 Correct 8 ms 15188 KB Output is correct
6 Correct 7 ms 15156 KB Output is correct
7 Correct 7 ms 15156 KB Output is correct
8 Correct 9 ms 15188 KB Output is correct
9 Correct 8 ms 15188 KB Output is correct
10 Correct 10 ms 15188 KB Output is correct
11 Correct 130 ms 34036 KB Output is correct
12 Correct 66 ms 26116 KB Output is correct
13 Correct 50 ms 26864 KB Output is correct
14 Correct 90 ms 31112 KB Output is correct
15 Correct 71 ms 29976 KB Output is correct
16 Correct 65 ms 29156 KB Output is correct
17 Correct 10 ms 15096 KB Output is correct
18 Correct 8 ms 15188 KB Output is correct
19 Correct 8 ms 15188 KB Output is correct
20 Correct 8 ms 15188 KB Output is correct
21 Correct 10 ms 15444 KB Output is correct
22 Correct 211 ms 37348 KB Output is correct
23 Correct 198 ms 37240 KB Output is correct
24 Correct 114 ms 27508 KB Output is correct
25 Correct 159 ms 31312 KB Output is correct
26 Correct 83 ms 30104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15188 KB Output is correct
2 Correct 10 ms 15144 KB Output is correct
3 Correct 9 ms 15160 KB Output is correct
4 Correct 8 ms 15092 KB Output is correct
5 Correct 8 ms 15188 KB Output is correct
6 Correct 7 ms 15156 KB Output is correct
7 Correct 7 ms 15156 KB Output is correct
8 Correct 9 ms 15188 KB Output is correct
9 Correct 8 ms 15188 KB Output is correct
10 Correct 10 ms 15188 KB Output is correct
11 Correct 130 ms 34036 KB Output is correct
12 Correct 66 ms 26116 KB Output is correct
13 Correct 50 ms 26864 KB Output is correct
14 Correct 90 ms 31112 KB Output is correct
15 Correct 71 ms 29976 KB Output is correct
16 Correct 65 ms 29156 KB Output is correct
17 Correct 10 ms 15096 KB Output is correct
18 Correct 8 ms 15188 KB Output is correct
19 Correct 8 ms 15188 KB Output is correct
20 Correct 8 ms 15188 KB Output is correct
21 Correct 10 ms 15444 KB Output is correct
22 Correct 211 ms 37348 KB Output is correct
23 Correct 198 ms 37240 KB Output is correct
24 Correct 114 ms 27508 KB Output is correct
25 Correct 159 ms 31312 KB Output is correct
26 Correct 83 ms 30104 KB Output is correct
27 Correct 8 ms 15188 KB Output is correct
28 Correct 9 ms 15188 KB Output is correct
29 Correct 8 ms 15188 KB Output is correct
30 Correct 9 ms 15228 KB Output is correct
31 Correct 17 ms 15640 KB Output is correct
32 Correct 9 ms 15316 KB Output is correct
33 Correct 8 ms 15328 KB Output is correct
34 Correct 422 ms 36916 KB Output is correct
35 Correct 352 ms 36452 KB Output is correct
36 Correct 383 ms 37660 KB Output is correct
37 Correct 277 ms 31312 KB Output is correct
38 Correct 175 ms 29912 KB Output is correct
39 Correct 62 ms 23332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15188 KB Output is correct
2 Correct 10 ms 15144 KB Output is correct
3 Correct 9 ms 15160 KB Output is correct
4 Correct 8 ms 15092 KB Output is correct
5 Correct 8 ms 15188 KB Output is correct
6 Correct 7 ms 15156 KB Output is correct
7 Correct 7 ms 15156 KB Output is correct
8 Correct 9 ms 15188 KB Output is correct
9 Correct 8 ms 15188 KB Output is correct
10 Correct 10 ms 15188 KB Output is correct
11 Correct 130 ms 34036 KB Output is correct
12 Correct 66 ms 26116 KB Output is correct
13 Correct 50 ms 26864 KB Output is correct
14 Correct 90 ms 31112 KB Output is correct
15 Correct 71 ms 29976 KB Output is correct
16 Correct 65 ms 29156 KB Output is correct
17 Correct 10 ms 15096 KB Output is correct
18 Correct 8 ms 15188 KB Output is correct
19 Correct 8 ms 15188 KB Output is correct
20 Correct 8 ms 15188 KB Output is correct
21 Correct 10 ms 15444 KB Output is correct
22 Correct 211 ms 37348 KB Output is correct
23 Correct 198 ms 37240 KB Output is correct
24 Correct 114 ms 27508 KB Output is correct
25 Correct 159 ms 31312 KB Output is correct
26 Correct 83 ms 30104 KB Output is correct
27 Correct 8 ms 15188 KB Output is correct
28 Correct 9 ms 15188 KB Output is correct
29 Correct 8 ms 15188 KB Output is correct
30 Correct 9 ms 15228 KB Output is correct
31 Correct 17 ms 15640 KB Output is correct
32 Correct 9 ms 15316 KB Output is correct
33 Correct 8 ms 15328 KB Output is correct
34 Correct 422 ms 36916 KB Output is correct
35 Correct 352 ms 36452 KB Output is correct
36 Correct 383 ms 37660 KB Output is correct
37 Correct 277 ms 31312 KB Output is correct
38 Correct 175 ms 29912 KB Output is correct
39 Correct 62 ms 23332 KB Output is correct
40 Correct 15 ms 15556 KB Output is correct
41 Correct 23 ms 15892 KB Output is correct
42 Correct 12 ms 15652 KB Output is correct
43 Correct 14 ms 15600 KB Output is correct
44 Correct 751 ms 37864 KB Output is correct
45 Correct 472 ms 31196 KB Output is correct
46 Correct 551 ms 33088 KB Output is correct
47 Correct 448 ms 33360 KB Output is correct
48 Correct 238 ms 31408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15188 KB Output is correct
2 Correct 8 ms 15188 KB Output is correct
3 Correct 7 ms 15188 KB Output is correct
4 Correct 8 ms 15188 KB Output is correct
5 Correct 8 ms 15188 KB Output is correct
6 Correct 9 ms 15188 KB Output is correct
7 Correct 8 ms 15188 KB Output is correct
8 Correct 8 ms 15188 KB Output is correct
9 Correct 8 ms 15188 KB Output is correct
10 Correct 8 ms 15152 KB Output is correct
11 Correct 7 ms 15092 KB Output is correct
12 Correct 8 ms 15188 KB Output is correct
13 Correct 7 ms 15188 KB Output is correct
14 Correct 8 ms 15188 KB Output is correct
15 Correct 8 ms 15188 KB Output is correct
16 Correct 8 ms 15208 KB Output is correct
17 Correct 8 ms 15216 KB Output is correct
18 Correct 8 ms 15188 KB Output is correct
19 Correct 9 ms 15188 KB Output is correct
20 Correct 8 ms 15188 KB Output is correct
21 Correct 10 ms 15188 KB Output is correct
22 Correct 8 ms 15188 KB Output is correct
23 Correct 8 ms 15188 KB Output is correct
24 Correct 9 ms 15188 KB Output is correct
25 Correct 10 ms 15188 KB Output is correct
26 Correct 26 ms 15960 KB Output is correct
27 Correct 23 ms 15892 KB Output is correct
28 Correct 21 ms 15812 KB Output is correct
29 Correct 17 ms 15676 KB Output is correct
30 Correct 16 ms 15564 KB Output is correct
31 Correct 21 ms 15912 KB Output is correct
32 Correct 15 ms 15600 KB Output is correct
33 Correct 13 ms 15572 KB Output is correct
34 Correct 13 ms 15836 KB Output is correct
35 Correct 8 ms 15316 KB Output is correct
36 Correct 9 ms 15248 KB Output is correct
37 Correct 12 ms 15596 KB Output is correct
38 Correct 12 ms 15572 KB Output is correct
39 Correct 10 ms 15444 KB Output is correct
40 Correct 8 ms 15188 KB Output is correct
41 Correct 10 ms 15144 KB Output is correct
42 Correct 9 ms 15160 KB Output is correct
43 Correct 8 ms 15092 KB Output is correct
44 Correct 8 ms 15188 KB Output is correct
45 Correct 7 ms 15156 KB Output is correct
46 Correct 7 ms 15156 KB Output is correct
47 Correct 9 ms 15188 KB Output is correct
48 Correct 8 ms 15188 KB Output is correct
49 Correct 10 ms 15188 KB Output is correct
50 Correct 130 ms 34036 KB Output is correct
51 Correct 66 ms 26116 KB Output is correct
52 Correct 50 ms 26864 KB Output is correct
53 Correct 90 ms 31112 KB Output is correct
54 Correct 71 ms 29976 KB Output is correct
55 Correct 65 ms 29156 KB Output is correct
56 Correct 10 ms 15096 KB Output is correct
57 Correct 8 ms 15188 KB Output is correct
58 Correct 8 ms 15188 KB Output is correct
59 Correct 8 ms 15188 KB Output is correct
60 Correct 10 ms 15444 KB Output is correct
61 Correct 211 ms 37348 KB Output is correct
62 Correct 198 ms 37240 KB Output is correct
63 Correct 114 ms 27508 KB Output is correct
64 Correct 159 ms 31312 KB Output is correct
65 Correct 83 ms 30104 KB Output is correct
66 Correct 8 ms 15188 KB Output is correct
67 Correct 9 ms 15188 KB Output is correct
68 Correct 8 ms 15188 KB Output is correct
69 Correct 9 ms 15228 KB Output is correct
70 Correct 17 ms 15640 KB Output is correct
71 Correct 9 ms 15316 KB Output is correct
72 Correct 8 ms 15328 KB Output is correct
73 Correct 422 ms 36916 KB Output is correct
74 Correct 352 ms 36452 KB Output is correct
75 Correct 383 ms 37660 KB Output is correct
76 Correct 277 ms 31312 KB Output is correct
77 Correct 175 ms 29912 KB Output is correct
78 Correct 62 ms 23332 KB Output is correct
79 Correct 15 ms 15556 KB Output is correct
80 Correct 23 ms 15892 KB Output is correct
81 Correct 12 ms 15652 KB Output is correct
82 Correct 14 ms 15600 KB Output is correct
83 Correct 751 ms 37864 KB Output is correct
84 Correct 472 ms 31196 KB Output is correct
85 Correct 551 ms 33088 KB Output is correct
86 Correct 448 ms 33360 KB Output is correct
87 Correct 238 ms 31408 KB Output is correct
88 Correct 1350 ms 46124 KB Output is correct
89 Correct 830 ms 41304 KB Output is correct
90 Correct 1123 ms 46452 KB Output is correct
91 Correct 602 ms 38044 KB Output is correct
92 Correct 863 ms 41332 KB Output is correct
93 Correct 775 ms 40420 KB Output is correct
94 Correct 625 ms 36080 KB Output is correct
95 Correct 402 ms 37292 KB Output is correct
96 Correct 383 ms 42264 KB Output is correct
97 Correct 68 ms 32960 KB Output is correct
98 Correct 273 ms 34968 KB Output is correct
99 Correct 288 ms 34988 KB Output is correct