Submission #587721

# Submission time Handle Problem Language Result Execution time Memory
587721 2022-07-02T09:26:18 Z Tekor Team Contest (JOI22_team) C++17
0 / 100
41 ms 5192 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],tekc;
ll t[N * 4],t1[N * 4];
vector <int> q;
void build(int v,int tl,int tr) {
	t1[v] = LLINF;
	if(tl == tr) {
		t[v] = LLINF;
		return;
	}
	int tm = (tl + tr) / 2;
	build(v + v,tl,tm);
	build(v + v + 1,tm + 1,tr);
	t[v] = LLINF;
}
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]);
}
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]);
	if(R > p)tekc = max(tekc,c[pos]);
	int lr = max(R + 1,p + 1);
	while(lr <= k && get(1,1,k,lr,k) < max(c[pos],tekc)) {
		R = lr;
		tekc = max(tekc,c[pos]);
		lr++;
	}
	lr = R + 1;
	while(lr <= k && get(1,1,k,lr,k) < tekc) {
		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:90:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |  for(int i = 1;i < q.size();i++) {
      |                ~~^~~~~~~~~~
team.cpp:98:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |  for(int i = 1;i < g.size();i++) {
      |                ~~^~~~~~~~~~
team.cpp:80:5: warning: unused variable 'mx' [-Wunused-variable]
   80 |  ll mx = 0;
      |     ^~
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 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 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 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 Incorrect 1 ms 340 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 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 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 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 Incorrect 1 ms 340 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 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 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 41 ms 5192 KB Output is correct
12 Incorrect 29 ms 3780 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 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 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 41 ms 5192 KB Output is correct
12 Incorrect 29 ms 3780 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 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 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 41 ms 5192 KB Output is correct
12 Incorrect 29 ms 3780 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 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 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 41 ms 5192 KB Output is correct
12 Incorrect 29 ms 3780 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 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 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 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 Incorrect 1 ms 340 KB Output isn't correct
26 Halted 0 ms 0 KB -