Submission #733681

# Submission time Handle Problem Language Result Execution time Memory
733681 2023-05-01T07:59:25 Z myrcella Team Contest (JOI22_team) C++17
100 / 100
721 ms 27908 KB
//by szh
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn = 2e5+10;
int n;
int x[maxn][3];
map <int,int> mp;
pii tree[2][maxn*4];
struct B{
	int a,b,c,id;
} beaver[maxn];

bool cmp1(B hi,B hii) {return hi.b<hii.b;}
bool cmp2(B hi,B hii) {return hi.a<hii.a;}

void update(int id,int c,int cl,int cr,int pos,pii val) {
	if (cl==cr) tree[id][c] = max(tree[id][c],val);
	else {
		int mid = cl+cr>>1;
		if (pos<=mid) update(id,c<<1,cl,mid,pos,val);
		else update(id,c<<1|1,mid+1,cr,pos,val);
		tree[id][c] = max(tree[id][c<<1],tree[id][c<<1|1]);
	}
}

pii query(int id,int c,int cl,int cr,int l,int r) {
	if (l<=cl and cr<=r) return tree[id][c];
	pii ret = {-1,-1};
	int mid=cl+cr>>1;
	if (l<=mid) ret = query(id,c<<1,cl,mid,l,r);
	if (r>mid) ret = max(ret,query(id,c<<1|1,mid+1,cr,l,r));
	return ret;
}

int main() {
//	freopen("input.txt","r",stdin);	
	std::ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	rep(i,0,n) rep(j,0,3) cin>>x[i][j];
	rep(j,0,3) {
		mp.clear();
		int tot = 0;
		rep(i,0,n) mp[x[i][j]] = 1;
		for (auto &it:mp) it.se = tot++;
		rep(i,0,n) {
			if (j==0) beaver[i].a = mp[x[i][j]];
			else if (j==1) beaver[i].b = mp[x[i][j]];
			else beaver[i].c = mp[x[i][j]];
		}
	}
	rep(i,0,n) beaver[i].id=i;
	//case 1: the beaver with highest Y has Z higher than the beaver with highest X
	sort(beaver,beaver+n,cmp1);
	int cur = 0;
	int ans = -1;
	rep(i,0,2) rep(j,0,maxn*4) tree[i][j] = {-1,-1};
	rep(i,0,n) {
		while (cur<n and beaver[cur].b<beaver[i].b) update(0,1,0,n-1,beaver[cur].a,{beaver[cur].c,beaver[cur].id}),update(1,1,0,n-1,beaver[cur].c,{beaver[cur].a,beaver[cur].id}),cur++;
		pii curx = query(1,1,0,n-1,0,beaver[i].c);
		if (curx.fi<=beaver[i].a) continue;
		pii curz = query(0,1,0,n-1,0,curx.fi-1);
		if (curz.fi<=beaver[i].c) continue;
		ans = max(ans,x[curx.se][0]+x[curz.se][2]+x[beaver[i].id][1]);
	}
	//case 2: the beaver with highest X has Z higher than the beaver with highest Y
	sort(beaver,beaver+n,cmp2);
	cur = 0;
	rep(i,0,2) rep(j,0,maxn*4) tree[i][j] = {-1,-1};
	rep(i,0,n) {
//		debug(beaver[i].id);
		while (cur<n and beaver[cur].a<beaver[i].a) update(0,1,0,n-1,beaver[cur].b,{beaver[cur].c,beaver[cur].id}),update(1,1,0,n-1,beaver[cur].c,{beaver[cur].b,beaver[cur].id}),cur++;
		pii cury = query(1,1,0,n-1,0,beaver[i].c);
		if (cury.fi<=beaver[i].b) continue;
		pii curz = query(0,1,0,n-1,0,cury.fi-1);
		if (curz.fi<=beaver[i].c) continue;
		ans = max(ans,x[cury.se][1]+x[curz.se][2]+x[beaver[i].id][0]);
	}
	cout<<ans;
	return 0;
}

Compilation message

team.cpp: In function 'void update(int, int, int, int, int, std::pair<int, int>)':
team.cpp:39:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |   int mid = cl+cr>>1;
      |             ~~^~~
team.cpp: In function 'std::pair<int, int> query(int, int, int, int, int, int)':
team.cpp:49:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |  int mid=cl+cr>>1;
      |          ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12756 KB Output is correct
2 Correct 9 ms 12756 KB Output is correct
3 Correct 9 ms 12756 KB Output is correct
4 Correct 8 ms 12756 KB Output is correct
5 Correct 8 ms 12756 KB Output is correct
6 Correct 8 ms 12868 KB Output is correct
7 Correct 8 ms 12756 KB Output is correct
8 Correct 8 ms 12756 KB Output is correct
9 Correct 8 ms 12756 KB Output is correct
10 Correct 8 ms 12756 KB Output is correct
11 Correct 9 ms 12884 KB Output is correct
12 Correct 8 ms 12756 KB Output is correct
13 Correct 9 ms 12756 KB Output is correct
14 Correct 9 ms 12824 KB Output is correct
15 Correct 9 ms 12800 KB Output is correct
16 Correct 8 ms 12856 KB Output is correct
17 Correct 12 ms 12808 KB Output is correct
18 Correct 9 ms 12880 KB Output is correct
19 Correct 9 ms 12876 KB Output is correct
20 Correct 9 ms 12764 KB Output is correct
21 Correct 8 ms 12824 KB Output is correct
22 Correct 9 ms 12884 KB Output is correct
23 Correct 8 ms 12760 KB Output is correct
24 Correct 9 ms 12756 KB Output is correct
25 Correct 9 ms 12760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12756 KB Output is correct
2 Correct 9 ms 12756 KB Output is correct
3 Correct 9 ms 12756 KB Output is correct
4 Correct 8 ms 12756 KB Output is correct
5 Correct 8 ms 12756 KB Output is correct
6 Correct 8 ms 12868 KB Output is correct
7 Correct 8 ms 12756 KB Output is correct
8 Correct 8 ms 12756 KB Output is correct
9 Correct 8 ms 12756 KB Output is correct
10 Correct 8 ms 12756 KB Output is correct
11 Correct 9 ms 12884 KB Output is correct
12 Correct 8 ms 12756 KB Output is correct
13 Correct 9 ms 12756 KB Output is correct
14 Correct 9 ms 12824 KB Output is correct
15 Correct 9 ms 12800 KB Output is correct
16 Correct 8 ms 12856 KB Output is correct
17 Correct 12 ms 12808 KB Output is correct
18 Correct 9 ms 12880 KB Output is correct
19 Correct 9 ms 12876 KB Output is correct
20 Correct 9 ms 12764 KB Output is correct
21 Correct 8 ms 12824 KB Output is correct
22 Correct 9 ms 12884 KB Output is correct
23 Correct 8 ms 12760 KB Output is correct
24 Correct 9 ms 12756 KB Output is correct
25 Correct 9 ms 12760 KB Output is correct
26 Correct 17 ms 13160 KB Output is correct
27 Correct 17 ms 13140 KB Output is correct
28 Correct 17 ms 13140 KB Output is correct
29 Correct 15 ms 13140 KB Output is correct
30 Correct 13 ms 13012 KB Output is correct
31 Correct 15 ms 13024 KB Output is correct
32 Correct 14 ms 13024 KB Output is correct
33 Correct 11 ms 13120 KB Output is correct
34 Correct 16 ms 13256 KB Output is correct
35 Correct 9 ms 12912 KB Output is correct
36 Correct 9 ms 12888 KB Output is correct
37 Correct 13 ms 13076 KB Output is correct
38 Correct 13 ms 13012 KB Output is correct
39 Correct 11 ms 12896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12756 KB Output is correct
2 Correct 9 ms 12756 KB Output is correct
3 Correct 8 ms 12756 KB Output is correct
4 Correct 8 ms 12756 KB Output is correct
5 Correct 9 ms 12756 KB Output is correct
6 Correct 8 ms 12756 KB Output is correct
7 Correct 9 ms 12796 KB Output is correct
8 Correct 8 ms 12752 KB Output is correct
9 Correct 8 ms 12760 KB Output is correct
10 Correct 9 ms 12756 KB Output is correct
11 Correct 176 ms 17732 KB Output is correct
12 Correct 109 ms 16076 KB Output is correct
13 Correct 126 ms 16852 KB Output is correct
14 Correct 157 ms 17832 KB Output is correct
15 Correct 103 ms 17824 KB Output is correct
16 Correct 68 ms 17720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12756 KB Output is correct
2 Correct 9 ms 12756 KB Output is correct
3 Correct 8 ms 12756 KB Output is correct
4 Correct 8 ms 12756 KB Output is correct
5 Correct 9 ms 12756 KB Output is correct
6 Correct 8 ms 12756 KB Output is correct
7 Correct 9 ms 12796 KB Output is correct
8 Correct 8 ms 12752 KB Output is correct
9 Correct 8 ms 12760 KB Output is correct
10 Correct 9 ms 12756 KB Output is correct
11 Correct 176 ms 17732 KB Output is correct
12 Correct 109 ms 16076 KB Output is correct
13 Correct 126 ms 16852 KB Output is correct
14 Correct 157 ms 17832 KB Output is correct
15 Correct 103 ms 17824 KB Output is correct
16 Correct 68 ms 17720 KB Output is correct
17 Correct 9 ms 12748 KB Output is correct
18 Correct 10 ms 12756 KB Output is correct
19 Correct 7 ms 12756 KB Output is correct
20 Correct 11 ms 12760 KB Output is correct
21 Correct 11 ms 12896 KB Output is correct
22 Correct 215 ms 18072 KB Output is correct
23 Correct 208 ms 17672 KB Output is correct
24 Correct 147 ms 16688 KB Output is correct
25 Correct 191 ms 17996 KB Output is correct
26 Correct 105 ms 17940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12756 KB Output is correct
2 Correct 9 ms 12756 KB Output is correct
3 Correct 8 ms 12756 KB Output is correct
4 Correct 8 ms 12756 KB Output is correct
5 Correct 9 ms 12756 KB Output is correct
6 Correct 8 ms 12756 KB Output is correct
7 Correct 9 ms 12796 KB Output is correct
8 Correct 8 ms 12752 KB Output is correct
9 Correct 8 ms 12760 KB Output is correct
10 Correct 9 ms 12756 KB Output is correct
11 Correct 176 ms 17732 KB Output is correct
12 Correct 109 ms 16076 KB Output is correct
13 Correct 126 ms 16852 KB Output is correct
14 Correct 157 ms 17832 KB Output is correct
15 Correct 103 ms 17824 KB Output is correct
16 Correct 68 ms 17720 KB Output is correct
17 Correct 9 ms 12748 KB Output is correct
18 Correct 10 ms 12756 KB Output is correct
19 Correct 7 ms 12756 KB Output is correct
20 Correct 11 ms 12760 KB Output is correct
21 Correct 11 ms 12896 KB Output is correct
22 Correct 215 ms 18072 KB Output is correct
23 Correct 208 ms 17672 KB Output is correct
24 Correct 147 ms 16688 KB Output is correct
25 Correct 191 ms 17996 KB Output is correct
26 Correct 105 ms 17940 KB Output is correct
27 Correct 8 ms 12880 KB Output is correct
28 Correct 10 ms 12884 KB Output is correct
29 Correct 8 ms 12756 KB Output is correct
30 Correct 8 ms 12756 KB Output is correct
31 Correct 13 ms 13004 KB Output is correct
32 Correct 9 ms 12888 KB Output is correct
33 Correct 9 ms 12804 KB Output is correct
34 Correct 261 ms 18380 KB Output is correct
35 Correct 228 ms 17884 KB Output is correct
36 Correct 257 ms 18372 KB Output is correct
37 Correct 234 ms 18588 KB Output is correct
38 Correct 110 ms 18380 KB Output is correct
39 Correct 77 ms 16196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12756 KB Output is correct
2 Correct 9 ms 12756 KB Output is correct
3 Correct 8 ms 12756 KB Output is correct
4 Correct 8 ms 12756 KB Output is correct
5 Correct 9 ms 12756 KB Output is correct
6 Correct 8 ms 12756 KB Output is correct
7 Correct 9 ms 12796 KB Output is correct
8 Correct 8 ms 12752 KB Output is correct
9 Correct 8 ms 12760 KB Output is correct
10 Correct 9 ms 12756 KB Output is correct
11 Correct 176 ms 17732 KB Output is correct
12 Correct 109 ms 16076 KB Output is correct
13 Correct 126 ms 16852 KB Output is correct
14 Correct 157 ms 17832 KB Output is correct
15 Correct 103 ms 17824 KB Output is correct
16 Correct 68 ms 17720 KB Output is correct
17 Correct 9 ms 12748 KB Output is correct
18 Correct 10 ms 12756 KB Output is correct
19 Correct 7 ms 12756 KB Output is correct
20 Correct 11 ms 12760 KB Output is correct
21 Correct 11 ms 12896 KB Output is correct
22 Correct 215 ms 18072 KB Output is correct
23 Correct 208 ms 17672 KB Output is correct
24 Correct 147 ms 16688 KB Output is correct
25 Correct 191 ms 17996 KB Output is correct
26 Correct 105 ms 17940 KB Output is correct
27 Correct 8 ms 12880 KB Output is correct
28 Correct 10 ms 12884 KB Output is correct
29 Correct 8 ms 12756 KB Output is correct
30 Correct 8 ms 12756 KB Output is correct
31 Correct 13 ms 13004 KB Output is correct
32 Correct 9 ms 12888 KB Output is correct
33 Correct 9 ms 12804 KB Output is correct
34 Correct 261 ms 18380 KB Output is correct
35 Correct 228 ms 17884 KB Output is correct
36 Correct 257 ms 18372 KB Output is correct
37 Correct 234 ms 18588 KB Output is correct
38 Correct 110 ms 18380 KB Output is correct
39 Correct 77 ms 16196 KB Output is correct
40 Correct 13 ms 13028 KB Output is correct
41 Correct 15 ms 13012 KB Output is correct
42 Correct 12 ms 13012 KB Output is correct
43 Correct 13 ms 13020 KB Output is correct
44 Correct 373 ms 19212 KB Output is correct
45 Correct 300 ms 19244 KB Output is correct
46 Correct 320 ms 19196 KB Output is correct
47 Correct 306 ms 19284 KB Output is correct
48 Correct 131 ms 19084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12756 KB Output is correct
2 Correct 9 ms 12756 KB Output is correct
3 Correct 9 ms 12756 KB Output is correct
4 Correct 8 ms 12756 KB Output is correct
5 Correct 8 ms 12756 KB Output is correct
6 Correct 8 ms 12868 KB Output is correct
7 Correct 8 ms 12756 KB Output is correct
8 Correct 8 ms 12756 KB Output is correct
9 Correct 8 ms 12756 KB Output is correct
10 Correct 8 ms 12756 KB Output is correct
11 Correct 9 ms 12884 KB Output is correct
12 Correct 8 ms 12756 KB Output is correct
13 Correct 9 ms 12756 KB Output is correct
14 Correct 9 ms 12824 KB Output is correct
15 Correct 9 ms 12800 KB Output is correct
16 Correct 8 ms 12856 KB Output is correct
17 Correct 12 ms 12808 KB Output is correct
18 Correct 9 ms 12880 KB Output is correct
19 Correct 9 ms 12876 KB Output is correct
20 Correct 9 ms 12764 KB Output is correct
21 Correct 8 ms 12824 KB Output is correct
22 Correct 9 ms 12884 KB Output is correct
23 Correct 8 ms 12760 KB Output is correct
24 Correct 9 ms 12756 KB Output is correct
25 Correct 9 ms 12760 KB Output is correct
26 Correct 17 ms 13160 KB Output is correct
27 Correct 17 ms 13140 KB Output is correct
28 Correct 17 ms 13140 KB Output is correct
29 Correct 15 ms 13140 KB Output is correct
30 Correct 13 ms 13012 KB Output is correct
31 Correct 15 ms 13024 KB Output is correct
32 Correct 14 ms 13024 KB Output is correct
33 Correct 11 ms 13120 KB Output is correct
34 Correct 16 ms 13256 KB Output is correct
35 Correct 9 ms 12912 KB Output is correct
36 Correct 9 ms 12888 KB Output is correct
37 Correct 13 ms 13076 KB Output is correct
38 Correct 13 ms 13012 KB Output is correct
39 Correct 11 ms 12896 KB Output is correct
40 Correct 8 ms 12756 KB Output is correct
41 Correct 9 ms 12756 KB Output is correct
42 Correct 8 ms 12756 KB Output is correct
43 Correct 8 ms 12756 KB Output is correct
44 Correct 9 ms 12756 KB Output is correct
45 Correct 8 ms 12756 KB Output is correct
46 Correct 9 ms 12796 KB Output is correct
47 Correct 8 ms 12752 KB Output is correct
48 Correct 8 ms 12760 KB Output is correct
49 Correct 9 ms 12756 KB Output is correct
50 Correct 176 ms 17732 KB Output is correct
51 Correct 109 ms 16076 KB Output is correct
52 Correct 126 ms 16852 KB Output is correct
53 Correct 157 ms 17832 KB Output is correct
54 Correct 103 ms 17824 KB Output is correct
55 Correct 68 ms 17720 KB Output is correct
56 Correct 9 ms 12748 KB Output is correct
57 Correct 10 ms 12756 KB Output is correct
58 Correct 7 ms 12756 KB Output is correct
59 Correct 11 ms 12760 KB Output is correct
60 Correct 11 ms 12896 KB Output is correct
61 Correct 215 ms 18072 KB Output is correct
62 Correct 208 ms 17672 KB Output is correct
63 Correct 147 ms 16688 KB Output is correct
64 Correct 191 ms 17996 KB Output is correct
65 Correct 105 ms 17940 KB Output is correct
66 Correct 8 ms 12880 KB Output is correct
67 Correct 10 ms 12884 KB Output is correct
68 Correct 8 ms 12756 KB Output is correct
69 Correct 8 ms 12756 KB Output is correct
70 Correct 13 ms 13004 KB Output is correct
71 Correct 9 ms 12888 KB Output is correct
72 Correct 9 ms 12804 KB Output is correct
73 Correct 261 ms 18380 KB Output is correct
74 Correct 228 ms 17884 KB Output is correct
75 Correct 257 ms 18372 KB Output is correct
76 Correct 234 ms 18588 KB Output is correct
77 Correct 110 ms 18380 KB Output is correct
78 Correct 77 ms 16196 KB Output is correct
79 Correct 13 ms 13028 KB Output is correct
80 Correct 15 ms 13012 KB Output is correct
81 Correct 12 ms 13012 KB Output is correct
82 Correct 13 ms 13020 KB Output is correct
83 Correct 373 ms 19212 KB Output is correct
84 Correct 300 ms 19244 KB Output is correct
85 Correct 320 ms 19196 KB Output is correct
86 Correct 306 ms 19284 KB Output is correct
87 Correct 131 ms 19084 KB Output is correct
88 Correct 721 ms 27900 KB Output is correct
89 Correct 519 ms 24756 KB Output is correct
90 Correct 601 ms 25288 KB Output is correct
91 Correct 449 ms 24024 KB Output is correct
92 Correct 440 ms 20608 KB Output is correct
93 Correct 502 ms 23748 KB Output is correct
94 Correct 433 ms 22232 KB Output is correct
95 Correct 202 ms 22476 KB Output is correct
96 Correct 561 ms 27908 KB Output is correct
97 Correct 91 ms 20868 KB Output is correct
98 Correct 258 ms 21772 KB Output is correct
99 Correct 253 ms 21840 KB Output is correct