Submission #587793

# Submission time Handle Problem Language Result Execution time Memory
587793 2022-07-02T11:23:20 Z LastRonin Team Contest (JOI22_team) C++14
18 / 100
445 ms 20688 KB
#pragma GCC optimize("O3")

#include <bits/stdc++.h> 
#define ll long long
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define pill pair<ll, ll>
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

const int N = 2e5 + 1;
const int M = 5E5 + 1;
const ll hsh[2] = {1555555699, 1222222763};
const ll P = 113;

int n;    
int a[N], b[N], c[N];
int sa[N], sb[N], sc[N];


struct node {
	node *l = nullptr, *r = nullptr;
	int val = 0;
} *Brt = new node(), *Crt = new node();

struct tdnode {
	tdnode *l = nullptr, *r = nullptr;
	node *val = nullptr;
	tdnode() {
		val = new node();
	}
} *tdrt = new tdnode();

vector<ll> scan[M];

void upd(int p, int z, node *v, int tl = 0, int tr = M + 1) {
	if(tl == tr) {
		v->val = max(v->val, z);
		return;
	}
	ll m = (tl + tr) >> 1ll;
	if(p <= m) {
		if(!v->l)v->l = new node();
		upd(p, z, v->l, tl, m);
	} else {
		if(!v->r)v->r = new node();
		upd(p, z, v->r, m + 1, tr);
	}
	v->val = max(v->val, z);
}
int get(int l, int r, node *v, int tl = 0, int tr = M + 1) {
	if(l > tr || tl > r || !v) 
		return 0;
	if(l <= tl && tr <= r) 
		return v->val;
	ll m = (tl + tr) >> 1ll;
	return max(get(l, r, v->l, tl, m), get(l, r, v->r, m + 1, tr));
}

void upd2(int x, int y, int z, tdnode *v, int tl = 0, int tr = M + 1) {
	if(tl == tr) {
		upd(y, z, v->val);
		return;
	}
	ll m = (tl + tr) >> 1ll;
	if(x <= m) {
		if(!v->l)v->l = new tdnode();
		upd2(x, y, z, v->l, tl, m);
	} else {
		if(!v->r)v->r = new tdnode();
		upd2(x, y, z, v->r, m + 1, tr);
	}
	upd(y, z, v->val);
}

int get2(int lx, int rx, int ly, int ry, tdnode *v, int tl = 0, int  tr = M + 1) {
	if(lx > tr || rx < tl || !v)return 0;
	if(lx <= tl && tr <= rx) {
		return get(ly, ry, v->val);
	}
	ll m = (tl + tr) >> 1ll;
	return max(get2(lx, rx, ly, ry, v->l, tl , m), get2(lx, rx, ly, ry, v->r, m + 1, tr));
}


bool comp2(int i, int j) {
	return b[i] < b[j];
}

bool comp1(int i, int j) {
	return c[i] < c[j];
}

int main() {
	speed;
	cin >> n;
	vector<int> g;
	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i] >> c[i];
		g.pb(a[i]);
		g.pb(b[i]);
		g.pb(c[i]);
	}
	sort(g.begin(), g.end());
	g.erase(unique(g.begin(), g.end()), g.end());
	for(int j = 1; j <= n; j++) {
		sa[j] = lower_bound(g.begin(), g.end(), a[j]) - g.begin() + 1;
		sb[j] = lower_bound(g.begin(), g.end(), b[j]) - g.begin() + 1;
		sc[j] = lower_bound(g.begin(), g.end(), c[j]) - g.begin() + 1;
		scan[sa[j]].pb(j);		
	}
	int sum = -1;
	for(int i = 1; i <= g.size(); i++) {
		for(auto u : scan[i]) {
			int z = get2(sb[u] + 1, M, sc[u] + 1, M, tdrt);		
			if(z)sum = max(sum, a[u] + z);
		}
		vector<pair<int, int>> aa;
		sort(scan[i].begin(), scan[i].end(), comp1);
		for(auto u : scan[i]) {
			upd(sc[u], b[u], Crt);	
			int gt2 = get(0, sc[u] - 1, Crt);
			if(gt2 > b[u])aa.pb(mp(gt2, c[u]));								
		}
		sort(scan[i].begin(), scan[i].end(), comp2);
		for(auto u : scan[i]) {
			upd(sb[u], c[u], Brt);
			int gt = get(0, sb[u] - 1, Brt);
			if(gt > c[u])aa.pb(mp(b[u], gt));
		}
		for(auto u : aa) {
			upd2(u.f, u.s, u.f + u.s, tdrt);
		}
	}
	cout << sum;
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:115:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |  for(int i = 1; i <= g.size(); i++) {
      |                 ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12076 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Correct 7 ms 12076 KB Output is correct
4 Correct 7 ms 12080 KB Output is correct
5 Correct 7 ms 12076 KB Output is correct
6 Correct 7 ms 12076 KB Output is correct
7 Correct 7 ms 12076 KB Output is correct
8 Correct 7 ms 11988 KB Output is correct
9 Correct 7 ms 12080 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 7 ms 11988 KB Output is correct
12 Correct 7 ms 12072 KB Output is correct
13 Correct 7 ms 12076 KB Output is correct
14 Incorrect 8 ms 12084 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12076 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Correct 7 ms 12076 KB Output is correct
4 Correct 7 ms 12080 KB Output is correct
5 Correct 7 ms 12076 KB Output is correct
6 Correct 7 ms 12076 KB Output is correct
7 Correct 7 ms 12076 KB Output is correct
8 Correct 7 ms 11988 KB Output is correct
9 Correct 7 ms 12080 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 7 ms 11988 KB Output is correct
12 Correct 7 ms 12072 KB Output is correct
13 Correct 7 ms 12076 KB Output is correct
14 Incorrect 8 ms 12084 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12036 KB Output is correct
2 Correct 8 ms 11988 KB Output is correct
3 Correct 8 ms 11988 KB Output is correct
4 Correct 7 ms 12072 KB Output is correct
5 Correct 7 ms 12056 KB Output is correct
6 Correct 7 ms 12076 KB Output is correct
7 Correct 7 ms 12056 KB Output is correct
8 Correct 7 ms 12040 KB Output is correct
9 Correct 8 ms 11988 KB Output is correct
10 Correct 8 ms 12060 KB Output is correct
11 Correct 319 ms 19696 KB Output is correct
12 Correct 153 ms 17284 KB Output is correct
13 Correct 81 ms 18108 KB Output is correct
14 Correct 231 ms 20288 KB Output is correct
15 Correct 171 ms 20688 KB Output is correct
16 Correct 79 ms 20236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12036 KB Output is correct
2 Correct 8 ms 11988 KB Output is correct
3 Correct 8 ms 11988 KB Output is correct
4 Correct 7 ms 12072 KB Output is correct
5 Correct 7 ms 12056 KB Output is correct
6 Correct 7 ms 12076 KB Output is correct
7 Correct 7 ms 12056 KB Output is correct
8 Correct 7 ms 12040 KB Output is correct
9 Correct 8 ms 11988 KB Output is correct
10 Correct 8 ms 12060 KB Output is correct
11 Correct 319 ms 19696 KB Output is correct
12 Correct 153 ms 17284 KB Output is correct
13 Correct 81 ms 18108 KB Output is correct
14 Correct 231 ms 20288 KB Output is correct
15 Correct 171 ms 20688 KB Output is correct
16 Correct 79 ms 20236 KB Output is correct
17 Correct 7 ms 11988 KB Output is correct
18 Correct 7 ms 12008 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 12116 KB Output is correct
21 Correct 13 ms 12244 KB Output is correct
22 Correct 445 ms 19068 KB Output is correct
23 Correct 349 ms 19100 KB Output is correct
24 Correct 221 ms 17472 KB Output is correct
25 Correct 268 ms 19684 KB Output is correct
26 Correct 165 ms 20376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12036 KB Output is correct
2 Correct 8 ms 11988 KB Output is correct
3 Correct 8 ms 11988 KB Output is correct
4 Correct 7 ms 12072 KB Output is correct
5 Correct 7 ms 12056 KB Output is correct
6 Correct 7 ms 12076 KB Output is correct
7 Correct 7 ms 12056 KB Output is correct
8 Correct 7 ms 12040 KB Output is correct
9 Correct 8 ms 11988 KB Output is correct
10 Correct 8 ms 12060 KB Output is correct
11 Correct 319 ms 19696 KB Output is correct
12 Correct 153 ms 17284 KB Output is correct
13 Correct 81 ms 18108 KB Output is correct
14 Correct 231 ms 20288 KB Output is correct
15 Correct 171 ms 20688 KB Output is correct
16 Correct 79 ms 20236 KB Output is correct
17 Correct 7 ms 11988 KB Output is correct
18 Correct 7 ms 12008 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 12116 KB Output is correct
21 Correct 13 ms 12244 KB Output is correct
22 Correct 445 ms 19068 KB Output is correct
23 Correct 349 ms 19100 KB Output is correct
24 Correct 221 ms 17472 KB Output is correct
25 Correct 268 ms 19684 KB Output is correct
26 Correct 165 ms 20376 KB Output is correct
27 Incorrect 8 ms 12500 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12036 KB Output is correct
2 Correct 8 ms 11988 KB Output is correct
3 Correct 8 ms 11988 KB Output is correct
4 Correct 7 ms 12072 KB Output is correct
5 Correct 7 ms 12056 KB Output is correct
6 Correct 7 ms 12076 KB Output is correct
7 Correct 7 ms 12056 KB Output is correct
8 Correct 7 ms 12040 KB Output is correct
9 Correct 8 ms 11988 KB Output is correct
10 Correct 8 ms 12060 KB Output is correct
11 Correct 319 ms 19696 KB Output is correct
12 Correct 153 ms 17284 KB Output is correct
13 Correct 81 ms 18108 KB Output is correct
14 Correct 231 ms 20288 KB Output is correct
15 Correct 171 ms 20688 KB Output is correct
16 Correct 79 ms 20236 KB Output is correct
17 Correct 7 ms 11988 KB Output is correct
18 Correct 7 ms 12008 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 12116 KB Output is correct
21 Correct 13 ms 12244 KB Output is correct
22 Correct 445 ms 19068 KB Output is correct
23 Correct 349 ms 19100 KB Output is correct
24 Correct 221 ms 17472 KB Output is correct
25 Correct 268 ms 19684 KB Output is correct
26 Correct 165 ms 20376 KB Output is correct
27 Incorrect 8 ms 12500 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12076 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Correct 7 ms 12076 KB Output is correct
4 Correct 7 ms 12080 KB Output is correct
5 Correct 7 ms 12076 KB Output is correct
6 Correct 7 ms 12076 KB Output is correct
7 Correct 7 ms 12076 KB Output is correct
8 Correct 7 ms 11988 KB Output is correct
9 Correct 7 ms 12080 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 7 ms 11988 KB Output is correct
12 Correct 7 ms 12072 KB Output is correct
13 Correct 7 ms 12076 KB Output is correct
14 Incorrect 8 ms 12084 KB Output isn't correct
15 Halted 0 ms 0 KB -