답안 #887621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887621 2023-12-14T20:38:35 Z Ahmed57 Team Contest (JOI22_team) C++17
100 / 100
1228 ms 116456 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define int long long
long long seg1[1800001],seg2[1800001];
pair<long long,long long> seg3[1800001],seg4[1800001];
 
void build(int p,int l,int r){
	seg1[p] = seg2[p] = -1e9;
	seg3[p] = {-1e9,-1e9};
	seg4[p] = {-1e9,-1e9};
    if(l==r){
        return ;
    }
    int md = (l+r)/2;
    build(p*2,l,md);build(p*2+1,md+1,r);
}
void update1(int p,int l,int r,int idx,long long val){
	if(l==r){
		seg1[p] = max(seg1[p],val);
		return ;
	}
	int md = (l+r)/2;
	if(idx<=md)update1(p*2,l,md,idx,val);
	else update1(p*2+1,md+1,r,idx,val);
	seg1[p] = max(seg1[p*2],seg1[p*2+1]);
}void update2(int p,int l,int r,int idx,long long val){
	if(l==r){
		seg2[p] = max(seg2[p],val);
		return ;
	}
	int md = (l+r)/2;
	if(idx<=md)update2(p*2,l,md,idx,val);
	else update2(p*2+1,md+1,r,idx,val);
	seg2[p] = max(seg2[p*2],seg2[p*2+1]);
}void update3(int p,int l,int r,int idx,long long val2,long long val){
	if(l==r){
		seg3[p] = max(seg3[p],make_pair(val,val+val2));
		return ;
	}
	int md = (l+r)/2;
	if(idx<=md)update3(p*2,l,md,idx,val2,val);
	else update3(p*2+1,md+1,r,idx,val2,val);
	seg3[p] = max(seg3[p*2],seg3[p*2+1]);
}void update4(int p,int l,int r,int idx,long long val2,long long val){
	if(l==r){
		seg4[p] = max(seg4[p],make_pair(val,val+val2));
		return ;
	}
	int md = (l+r)/2;
	if(idx<=md)update4(p*2,l,md,idx,val2,val);
	else update4(p*2+1,md+1,r,idx,val2,val);
	seg4[p] = max(seg4[p*2],seg4[p*2+1]);
}
long long query1(int p,int l,int r,int lq,int rq){
	if(r<lq||l>rq||lq>rq)return -1e9;
    if(l>=lq&&r<=rq)return seg1[p];
    int md = (l+r)/2;
    return max(query1(p*2,l,md,lq,rq),query1(p*2+1,md+1,r,lq,rq));
}long long query2(int p,int l,int r,int lq,int rq){
	if(r<lq||l>rq||lq>rq)return -1e9;
    if(l>=lq&&r<=rq)return seg2[p];
    int md = (l+r)/2;
    return max(query2(p*2,l,md,lq,rq),query2(p*2+1,md+1,r,lq,rq));
}long long query3(int p,int l,int r,int lq,int rq,int limit){
	if(r<lq||l>rq||lq>rq)return -1e9;
    if(l>=lq&&r<=rq){
    	if(seg3[p].first>limit)return seg3[p].second;
    	else return -1e9;
    }
    int md = (l+r)/2;
    return max(query3(p*2,l,md,lq,rq,limit),query3(p*2+1,md+1,r,lq,rq,limit));
}long long query4(int p,int l,int r,int lq,int rq,int limit){
	if(r<lq||l>rq||lq>rq)return -1e9;
    if(l>=lq&&r<=rq){
    	if(seg4[p].first>limit)return seg4[p].second;
    	else return -1e9;
    }
    int md = (l+r)/2;
    return max(query4(p*2,l,md,lq,rq,limit),query4(p*2+1,md+1,r,lq,rq,limit));
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	vector<array<long long,3>> v;
	map<int,int> mp,sav;
	for(int i = 0;i<n;i++){
		long long a,b,c;cin>>a>>b>>c;
		v.push_back({a,b,c});
		mp[a]++;
		mp[b]++;
		mp[c]++;
	}
	int cnt = 0;
	for(auto i:mp){
		sav[i.first] = ++cnt;
	}
	sort(v.begin(),v.end());
	int ind = 0;
	long long ans = -1e9;
	build(1,1,cnt);
	for(int i = 0;i<n;i++){
        while(v[ind][0]<v[i][0]){
            {//taking first as max
                long long val = query1(1,1,cnt,1,sav[v[ind][1]]-1);
                if(val>v[ind][2]){
                	update3(1,1,cnt,sav[v[ind][1]],v[ind][1],val);
                }
            }
            {
                long long val = query2(1,1,cnt,1,sav[v[ind][2]]-1);
                if(val>v[ind][1]){
                	update4(1,1,cnt,sav[v[ind][2]],v[ind][2],val);
                }
            }
            update1(1,1,cnt,sav[v[ind][1]],v[ind][2]);
            update2(1,1,cnt,sav[v[ind][2]],v[ind][1]);
            ind++;
        }
        ans = max(ans,v[i][0]+max(query3(1,1,cnt,sav[v[i][1]]+1,cnt,v[i][2]),query4(1,1,cnt,sav[v[i][2]]+1,cnt,v[i][1])));
	}
	cout<<(ans<0?-1:ans)<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6612 KB Output is correct
11 Correct 1 ms 6616 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6612 KB Output is correct
11 Correct 1 ms 6616 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 15 ms 10332 KB Output is correct
27 Correct 11 ms 9820 KB Output is correct
28 Correct 11 ms 9756 KB Output is correct
29 Correct 8 ms 9564 KB Output is correct
30 Correct 6 ms 7004 KB Output is correct
31 Correct 7 ms 6748 KB Output is correct
32 Correct 5 ms 6748 KB Output is correct
33 Correct 5 ms 7004 KB Output is correct
34 Correct 10 ms 10332 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 4 ms 6748 KB Output is correct
38 Correct 4 ms 6940 KB Output is correct
39 Correct 3 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 50 ms 10944 KB Output is correct
12 Correct 31 ms 8908 KB Output is correct
13 Correct 34 ms 9672 KB Output is correct
14 Correct 48 ms 12220 KB Output is correct
15 Correct 40 ms 11960 KB Output is correct
16 Correct 31 ms 10424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 50 ms 10944 KB Output is correct
12 Correct 31 ms 8908 KB Output is correct
13 Correct 34 ms 9672 KB Output is correct
14 Correct 48 ms 12220 KB Output is correct
15 Correct 40 ms 11960 KB Output is correct
16 Correct 31 ms 10424 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 91 ms 11548 KB Output is correct
23 Correct 69 ms 10808 KB Output is correct
24 Correct 48 ms 9296 KB Output is correct
25 Correct 64 ms 10940 KB Output is correct
26 Correct 43 ms 11200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 50 ms 10944 KB Output is correct
12 Correct 31 ms 8908 KB Output is correct
13 Correct 34 ms 9672 KB Output is correct
14 Correct 48 ms 12220 KB Output is correct
15 Correct 40 ms 11960 KB Output is correct
16 Correct 31 ms 10424 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 91 ms 11548 KB Output is correct
23 Correct 69 ms 10808 KB Output is correct
24 Correct 48 ms 9296 KB Output is correct
25 Correct 64 ms 10940 KB Output is correct
26 Correct 43 ms 11200 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6488 KB Output is correct
31 Correct 5 ms 6748 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 160 ms 10964 KB Output is correct
35 Correct 135 ms 10428 KB Output is correct
36 Correct 159 ms 12140 KB Output is correct
37 Correct 120 ms 10212 KB Output is correct
38 Correct 79 ms 10380 KB Output is correct
39 Correct 38 ms 8844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 50 ms 10944 KB Output is correct
12 Correct 31 ms 8908 KB Output is correct
13 Correct 34 ms 9672 KB Output is correct
14 Correct 48 ms 12220 KB Output is correct
15 Correct 40 ms 11960 KB Output is correct
16 Correct 31 ms 10424 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 91 ms 11548 KB Output is correct
23 Correct 69 ms 10808 KB Output is correct
24 Correct 48 ms 9296 KB Output is correct
25 Correct 64 ms 10940 KB Output is correct
26 Correct 43 ms 11200 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6488 KB Output is correct
31 Correct 5 ms 6748 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 160 ms 10964 KB Output is correct
35 Correct 135 ms 10428 KB Output is correct
36 Correct 159 ms 12140 KB Output is correct
37 Correct 120 ms 10212 KB Output is correct
38 Correct 79 ms 10380 KB Output is correct
39 Correct 38 ms 8844 KB Output is correct
40 Correct 6 ms 7116 KB Output is correct
41 Correct 7 ms 6748 KB Output is correct
42 Correct 4 ms 6804 KB Output is correct
43 Correct 4 ms 6748 KB Output is correct
44 Correct 296 ms 12460 KB Output is correct
45 Correct 218 ms 11256 KB Output is correct
46 Correct 241 ms 12020 KB Output is correct
47 Correct 240 ms 11540 KB Output is correct
48 Correct 82 ms 12028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6612 KB Output is correct
11 Correct 1 ms 6616 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 15 ms 10332 KB Output is correct
27 Correct 11 ms 9820 KB Output is correct
28 Correct 11 ms 9756 KB Output is correct
29 Correct 8 ms 9564 KB Output is correct
30 Correct 6 ms 7004 KB Output is correct
31 Correct 7 ms 6748 KB Output is correct
32 Correct 5 ms 6748 KB Output is correct
33 Correct 5 ms 7004 KB Output is correct
34 Correct 10 ms 10332 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 4 ms 6748 KB Output is correct
38 Correct 4 ms 6940 KB Output is correct
39 Correct 3 ms 6492 KB Output is correct
40 Correct 1 ms 6744 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 50 ms 10944 KB Output is correct
51 Correct 31 ms 8908 KB Output is correct
52 Correct 34 ms 9672 KB Output is correct
53 Correct 48 ms 12220 KB Output is correct
54 Correct 40 ms 11960 KB Output is correct
55 Correct 31 ms 10424 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
57 Correct 1 ms 6492 KB Output is correct
58 Correct 1 ms 6492 KB Output is correct
59 Correct 1 ms 6492 KB Output is correct
60 Correct 2 ms 6492 KB Output is correct
61 Correct 91 ms 11548 KB Output is correct
62 Correct 69 ms 10808 KB Output is correct
63 Correct 48 ms 9296 KB Output is correct
64 Correct 64 ms 10940 KB Output is correct
65 Correct 43 ms 11200 KB Output is correct
66 Correct 1 ms 6492 KB Output is correct
67 Correct 1 ms 6492 KB Output is correct
68 Correct 1 ms 6492 KB Output is correct
69 Correct 1 ms 6488 KB Output is correct
70 Correct 5 ms 6748 KB Output is correct
71 Correct 1 ms 6492 KB Output is correct
72 Correct 1 ms 6492 KB Output is correct
73 Correct 160 ms 10964 KB Output is correct
74 Correct 135 ms 10428 KB Output is correct
75 Correct 159 ms 12140 KB Output is correct
76 Correct 120 ms 10212 KB Output is correct
77 Correct 79 ms 10380 KB Output is correct
78 Correct 38 ms 8844 KB Output is correct
79 Correct 6 ms 7116 KB Output is correct
80 Correct 7 ms 6748 KB Output is correct
81 Correct 4 ms 6804 KB Output is correct
82 Correct 4 ms 6748 KB Output is correct
83 Correct 296 ms 12460 KB Output is correct
84 Correct 218 ms 11256 KB Output is correct
85 Correct 241 ms 12020 KB Output is correct
86 Correct 240 ms 11540 KB Output is correct
87 Correct 82 ms 12028 KB Output is correct
88 Correct 1228 ms 116456 KB Output is correct
89 Correct 730 ms 67820 KB Output is correct
90 Correct 938 ms 95732 KB Output is correct
91 Correct 567 ms 61460 KB Output is correct
92 Correct 396 ms 19700 KB Output is correct
93 Correct 558 ms 52604 KB Output is correct
94 Correct 414 ms 33296 KB Output is correct
95 Correct 181 ms 36880 KB Output is correct
96 Correct 620 ms 116208 KB Output is correct
97 Correct 53 ms 10652 KB Output is correct
98 Correct 228 ms 20724 KB Output is correct
99 Correct 216 ms 22688 KB Output is correct