제출 #1171994

#제출 시각아이디문제언어결과실행 시간메모리
1171994harryleeTeam Contest (JOI22_team)C++20
0 / 100
342 ms32184 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 150000; const int maxval = 450000; int n, l, r, m, c, res = -1; struct beaver{ int X, Y, Z; }; beaver a[maxn]; vector<int> v; struct str{ int max, min; inline str(){ max = -1e9; min = 1e9; } }; str operator + (const str& x, const str& y){ str ans; ans.max = max(x.max, y.max); ans.min = min(x.min, y.min); return ans; } class segment_tree{ private: vector<str> st; void update(int id, int l, int r, int i, int val){ if (i > r || i < l) return; if (l == r){ st[id].max = max(st[id].max, val); st[id].min = min(st[id].min, val); return; } int mid = (l + r) >> 1; update(id * 2, l, mid, i, val); update(id * 2 + 1, mid + 1, r, i, val); st[id] = st[id * 2] + st[id * 2 + 1]; return; } int get(int id, int l, int r, int u, int v, bool maxx){ if (l > v || r < u){ if (maxx) return -1e9; return 1e9; } if (l >= u && r <= v){ if (maxx) return st[id].max; return st[id].min; } int mid = (l + r) >> 1; if (maxx) return max(get(id * 2, l, mid, u, v, maxx), get(id * 2 + 1, mid + 1, r, u, v, maxx)); return min(get(id * 2, l, mid, u, v, maxx), get(id * 2 + 1, mid + 1, r, u, v, maxx)); } public: inline segment_tree(){ st.resize(maxval << 2); } void update(int i, int val){ update(1, 1, maxval, i, val); } int getmax(int u, int v){ return get(1, 1, maxval, u, v, 1); } int getmin(int u, int v){ return get(1, 1, maxval, u, v, 0); } } st1, st2; bool comp(const beaver& x, const beaver& y){ return (x.X < y.X); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; ++i){ cin >> a[i].X >> a[i].Y >> a[i].Z; v.push_back(a[i].X); v.push_back(a[i].Y); v.push_back(a[i].Z); } sort(v.begin(), v.end()); auto it = unique(v.begin(), v.end()); v.erase(it, v.end()); sort(a, a + n, comp); for (int i = 0, j = 0; i < n; ++i){ a[i].X = lower_bound(v.begin(), v.end(), a[i].X) - v.begin() + 1; a[i].Y = lower_bound(v.begin(), v.end(), a[i].Y) - v.begin() + 1; a[i].Z = lower_bound(v.begin(), v.end(), a[i].Z) - v.begin() + 1; while (a[j].X != a[i].X){ st1.update(a[j].Y, a[j].Z); c = st1.getmax(1, a[j].Y - 1); if (c > a[j].Z){ st2.update(a[j].Y, c); } l = a[j].Y + 1; r = maxval; int ans = -1; while (l <= r){ m = (l + r) >> 1; if (st1.getmin(m, maxval) < a[j].Z){ ans = m; l = m + 1; } else r = m - 1; } if (ans != -1){ st2.update(m, a[j].Z); } j++; } l = a[i].Y + 1; r = maxval; int ans = -1; while (l <= r){ m = (l + r) >> 1; if (st2.getmax(m, maxval) > a[i].Z){ ans = m; l = m + 1; } else r = m - 1; } if (ans != -1){ res = max(res, v[a[i].X - 1] + v[ans - 1] + v[st2.getmax(ans, maxval) - 1]); } } cout << res; }
#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...