답안 #587723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587723 2022-07-02T09:33:29 Z Tekor Team Contest (JOI22_team) C++17
100 / 100
324 ms 30636 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
void boos() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
const int N = 2e5 + 100;
const ll LLINF = (ll)1e18;
map <int,int> was;
int n,k,R;
ll a[N],b[N],c[N],d[N],sv[N],tekc;
ll t[N * 4],t1[N * 4],t2[N * 4];
vector <int> q;
void build(int v,int tl,int tr) {
	t1[v] = LLINF;
	t[v] = LLINF;
	t2[v] = 0;
	if(tl == tr)return;
	int tm = (tl + tr) / 2;
	build(v + v,tl,tm);
	build(v + v + 1,tm + 1,tr);
}
void push(int v) {
	t[v + v] = min(t[v + v],t1[v]);
	t[v + v + 1] = min(t[v + v + 1],t1[v]);
	t1[v + v] = min(t1[v + v],t1[v]);
	t1[v + v + 1] = min(t1[v + v + 1],t1[v]);
}
void upd(int v,int tl,int tr,int l,int r,ll x) {
	if(tl > r || tr < l)return;
	if(tl >= l && tr <= r) {
		t1[v] = min(t1[v],x);
		t[v] = min(t[v],x);
		return;
	}
	push(v);
	int tm = (tl + tr) / 2;
	upd(v + v,tl,tm,l,r,x);
	upd(v + v + 1,tm + 1,tr,l,r,x);
	t[v] = min(t[v + v],t[v + v + 1]);
}
void upd1(int v,int tl,int tr,int pos,ll x) {
	if(tl == tr) {
		t2[v] = max(t2[v],x);
		return;
	}
	int tm = (tl + tr) / 2;
	if(pos <= tm)upd1(v + v,tl,tm,pos,x);
	else upd1(v + v + 1,tm + 1,tr,pos,x);
	t2[v] = max(t2[v + v],t2[v + v + 1]);
}
ll get1(int v,int tl,int tr,int l,int r) {
	if(tl > r || tr < l)return 0;
	if(tl >= l && tr <= r)return t2[v];
	int tm = (tl + tr) / 2;
	return max(get1(v + v,tl,tm,l,r),get1(v + v + 1,tm + 1,tr,l,r));
}
ll get(int v,int tl,int tr,int l,int r) {
	if(tl > r || tr < l)return LLINF;
	if(tl >= l && tr <= r) {
		return t[v];
	}
	push(v);
	int tm = (tl + tr) / 2;
	return min(get(v + v,tl,tm,l,r),get(v + v + 1,tm + 1,tr,l,r));
}
bool cmp(int x,int y) {
	return a[x] < a[y];
}
void add(int pos) {
	int p = was[b[pos]];
	upd(1,1,k,1,p,c[pos]);
	upd1(1,1,k,p,c[pos]);
	sv[p] = max(sv[p],c[pos]);
	if(R > p)tekc = max(tekc,c[pos]);
	if(p > R) {
		int lr = p;
		while(lr <= k && get(1,1,k,lr,k) < get1(1,1,k,1,lr - 1)) {
			tekc = max(tekc,get1(1,1,k,1,lr - 1));
			R = lr;
			lr++;
		}
		if(lr == p) {
			lr++;
			while(lr <= k && get(1,1,k,lr,k) < get1(1,1,k,1,lr - 1)) {
				tekc = max(tekc,get1(1,1,k,1,lr - 1));
				R = lr;
				lr++;
			}
		}
	}
	int lr = R + 1;
	while(lr <= k && get(1,1,k,lr,k) < tekc) {
		tekc = max(tekc,get1(1,1,k,1,lr - 1));
		R = lr;
		lr++;
	}
	
}
void solve() {
	cin >> n;
	vector <int> g;
	ll mx = 0;
	for(int i = 1;i <= n;i++) {
		cin >> a[i] >> b[i] >> c[i];
		q.pb(b[i]);
		g.pb(i);
	}
	sort(all(g),cmp);
	sort(all(q));
	was[q[0]] = ++k;
	d[k] = q[0];
	for(int i = 1;i < q.size();i++) {
		if(q[i] != q[i - 1])was[q[i]] = ++k;
		d[k] = q[i];
	}
	build(1,1,k);
	ll ans = -1;
	R = 0;
	tekc = -LLINF;
	for(int i = 1;i < g.size();i++) {
		if(a[g[i - 1]] != a[g[i]]) {
			int pos = i - 1;
			while(pos >= 0 && a[g[pos]] == a[g[i - 1]]) {
				add(g[pos]);
				//cout << g[pos] << " dob" << endl;
				pos--;
			}
		}
		if(tekc > c[g[i]] && d[R] > b[g[i]])ans = max(ans,a[g[i]] + tekc + d[R]);
		//cout << ans << " -- " << a[g[i]] << " " << d[R] << " " << tekc << " " << R << endl;
	}
	cout << ans;
}
int main() {
	boos();
	solve();
}

Compilation message

team.cpp: In function 'void solve()':
team.cpp:117:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |  for(int i = 1;i < q.size();i++) {
      |                ~~^~~~~~~~~~
team.cpp:125:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |  for(int i = 1;i < g.size();i++) {
      |                ~~^~~~~~~~~~
team.cpp:107:5: warning: unused variable 'mx' [-Wunused-variable]
  107 |  ll mx = 0;
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 980 KB Output is correct
27 Correct 5 ms 948 KB Output is correct
28 Correct 6 ms 860 KB Output is correct
29 Correct 5 ms 788 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 6 ms 684 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 2 ms 676 KB Output is correct
34 Correct 5 ms 1036 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 4 ms 724 KB Output is correct
38 Correct 6 ms 724 KB Output is correct
39 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 51 ms 5260 KB Output is correct
12 Correct 29 ms 3648 KB Output is correct
13 Correct 39 ms 4552 KB Output is correct
14 Correct 48 ms 5400 KB Output is correct
15 Correct 39 ms 5428 KB Output is correct
16 Correct 37 ms 5380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 51 ms 5260 KB Output is correct
12 Correct 29 ms 3648 KB Output is correct
13 Correct 39 ms 4552 KB Output is correct
14 Correct 48 ms 5400 KB Output is correct
15 Correct 39 ms 5428 KB Output is correct
16 Correct 37 ms 5380 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 57 ms 5388 KB Output is correct
23 Correct 55 ms 5296 KB Output is correct
24 Correct 47 ms 4020 KB Output is correct
25 Correct 76 ms 5380 KB Output is correct
26 Correct 37 ms 5412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 51 ms 5260 KB Output is correct
12 Correct 29 ms 3648 KB Output is correct
13 Correct 39 ms 4552 KB Output is correct
14 Correct 48 ms 5400 KB Output is correct
15 Correct 39 ms 5428 KB Output is correct
16 Correct 37 ms 5380 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 57 ms 5388 KB Output is correct
23 Correct 55 ms 5296 KB Output is correct
24 Correct 47 ms 4020 KB Output is correct
25 Correct 76 ms 5380 KB Output is correct
26 Correct 37 ms 5412 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 79 ms 5488 KB Output is correct
35 Correct 88 ms 5576 KB Output is correct
36 Correct 106 ms 5552 KB Output is correct
37 Correct 104 ms 5732 KB Output is correct
38 Correct 44 ms 5636 KB Output is correct
39 Correct 20 ms 3908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 51 ms 5260 KB Output is correct
12 Correct 29 ms 3648 KB Output is correct
13 Correct 39 ms 4552 KB Output is correct
14 Correct 48 ms 5400 KB Output is correct
15 Correct 39 ms 5428 KB Output is correct
16 Correct 37 ms 5380 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 57 ms 5388 KB Output is correct
23 Correct 55 ms 5296 KB Output is correct
24 Correct 47 ms 4020 KB Output is correct
25 Correct 76 ms 5380 KB Output is correct
26 Correct 37 ms 5412 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 79 ms 5488 KB Output is correct
35 Correct 88 ms 5576 KB Output is correct
36 Correct 106 ms 5552 KB Output is correct
37 Correct 104 ms 5732 KB Output is correct
38 Correct 44 ms 5636 KB Output is correct
39 Correct 20 ms 3908 KB Output is correct
40 Correct 3 ms 596 KB Output is correct
41 Correct 4 ms 724 KB Output is correct
42 Correct 4 ms 720 KB Output is correct
43 Correct 5 ms 724 KB Output is correct
44 Correct 128 ms 7576 KB Output is correct
45 Correct 156 ms 5764 KB Output is correct
46 Correct 137 ms 5588 KB Output is correct
47 Correct 137 ms 5660 KB Output is correct
48 Correct 57 ms 5600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 980 KB Output is correct
27 Correct 5 ms 948 KB Output is correct
28 Correct 6 ms 860 KB Output is correct
29 Correct 5 ms 788 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 6 ms 684 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 2 ms 676 KB Output is correct
34 Correct 5 ms 1036 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 4 ms 724 KB Output is correct
38 Correct 6 ms 724 KB Output is correct
39 Correct 1 ms 464 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 51 ms 5260 KB Output is correct
51 Correct 29 ms 3648 KB Output is correct
52 Correct 39 ms 4552 KB Output is correct
53 Correct 48 ms 5400 KB Output is correct
54 Correct 39 ms 5428 KB Output is correct
55 Correct 37 ms 5380 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 57 ms 5388 KB Output is correct
62 Correct 55 ms 5296 KB Output is correct
63 Correct 47 ms 4020 KB Output is correct
64 Correct 76 ms 5380 KB Output is correct
65 Correct 37 ms 5412 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 3 ms 596 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 79 ms 5488 KB Output is correct
74 Correct 88 ms 5576 KB Output is correct
75 Correct 106 ms 5552 KB Output is correct
76 Correct 104 ms 5732 KB Output is correct
77 Correct 44 ms 5636 KB Output is correct
78 Correct 20 ms 3908 KB Output is correct
79 Correct 3 ms 596 KB Output is correct
80 Correct 4 ms 724 KB Output is correct
81 Correct 4 ms 720 KB Output is correct
82 Correct 5 ms 724 KB Output is correct
83 Correct 128 ms 7576 KB Output is correct
84 Correct 156 ms 5764 KB Output is correct
85 Correct 137 ms 5588 KB Output is correct
86 Correct 137 ms 5660 KB Output is correct
87 Correct 57 ms 5600 KB Output is correct
88 Correct 311 ms 28520 KB Output is correct
89 Correct 277 ms 20280 KB Output is correct
90 Correct 324 ms 21048 KB Output is correct
91 Correct 264 ms 19268 KB Output is correct
92 Correct 201 ms 10736 KB Output is correct
93 Correct 312 ms 19444 KB Output is correct
94 Correct 236 ms 14116 KB Output is correct
95 Correct 96 ms 13884 KB Output is correct
96 Correct 288 ms 30636 KB Output is correct
97 Correct 49 ms 9180 KB Output is correct
98 Correct 171 ms 13748 KB Output is correct
99 Correct 241 ms 13772 KB Output is correct