This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |