Submission #545330

#TimeUsernameProblemLanguageResultExecution timeMemory
545330MeloricTeam Contest (JOI22_team)C++14
0 / 100
2082 ms6596 KiB
#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#define pii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

using namespace std;

const int inf  = 1e18;

struct triple{
	int x, y, z;
	void p(){
		cout << x << ' '<< y << ' '<< z << '\n';
	}
};

void solve(){
	int n; cin >> n;
	vector<triple>A;
	for(int i = 0; i< n; i++){
		int x, y, z; cin >> x >> y >> z;
		A.pb({x, y, z});
	}
	sort(all(A), [](const triple& a, const triple& b){return a.z < b.z;});
	int by = -1;
	int bx = -1;
	int ans = -1;
	
	set<pii> S;
	
	for(int i = 0; i< n;){
		deque<triple> q;
		for(; i< n && (q.empty() || q.back().z == A[i].z); i++)q.pb(A[i]);
		for(auto& e : q){
			int x = e.x;
			int y = e.y;
			int z = e.z;
			
			if(by != -1 && bx != -1 && by > y && bx > x)ans = by+bx+z;
		}
		for(auto& e : q){
			int x = e.x;
			int y = e.y;
			
			if(x <= bx && y <= by)continue;
			if(x > bx && y < by)bx = x;
			if(x < bx && y > by)by = y;

			auto it = S.lb({x, -inf});
			if(it != S.begin()){
				it--;
				if((*it).Y > y){
					bx = x;
					by = (*it).Y;
				}
			}
			it = S.lb({x, inf});
			if(it != S.end()){
				while(next(it) != S.end() && (*next(it)).Y < y)it++;
				bx = (*it).X;
				by = y;
			}
			S.insert({x, y});
			while(S.size() && (*S.begin()).X <= bx || (*S.begin()).Y <= by)S.erase(S.begin());
		}
	}
	cout << ans;
}

	
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t = 1;
	//cin >> t;
	while(t--)solve();
}

Compilation message (stderr)

team.cpp: In function 'void solve()':
team.cpp:69:19: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   69 |    while(S.size() && (*S.begin()).X <= bx || (*S.begin()).Y <= by)S.erase(S.begin());
      |          ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...