#include <bits/stdc++.h>
using namespace std;
#define task "a"
#define etr "\n"
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define bg begin
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define lwb lower_bound
#define upb upper_bound
#define range(x, l, r) x+l, x+1+r
#define all(x) (x).bg(), (x).end()
#define compact(x) x.resize(unique(all(x)) - (x).bg())
#define sq(x) ((x)*(x))
auto start = chrono::high_resolution_clock::now();
void start_timer()
{
start = chrono::high_resolution_clock::now();
}
ld elapsed()
{
auto current = chrono::high_resolution_clock::now();
ld duration = chrono::duration_cast<chrono::nanoseconds>(current - start).count();
return duration / 1e9;
}
void freop()
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
template<class U, class V> istream& operator >> (istream& in, pair<U, V>& p)
{
in >> p.fi >> p.se;
return in;
}
template<class U, class V> ostream& operator << (ostream& out, pair<U, V> p)
{
out << "{" << p.fi << ' ' << p.se << "}";
return out;
}
template<class T> ostream& operator << (ostream& out, vector<T>& v)
{
out << "{";
for (int i=0; i<v.size(); i++)
{
out << v[i];
if (i != v.size() - 1) out << ", ";
}
out << "}";
return out;
}
template<class T, long long unsigned int N> ostream& operator << (ostream& out, array<T, N>& v)
{
out << "{";
for (int i=0; i<N; i++)
{
out << v[i];
if (i != N - 1) out << ", ";
}
out << "}";
return out;
}
const int N=2e5, M=1e5, mod=1e9+7;
int n;
array<int, 3> a[N+5];
vector<int> ys, zs;
struct Fenwick
{
int bit[N+5];
Fenwick()
{
memset(bit, 0, sizeof(bit));
}
void update(int idx, int val)
{
for (; idx<=n; idx+=idx&-idx) bit[idx] = max(bit[idx], val);
}
int get(int idx)
{
int res = 0;
for (; idx; idx-=idx&-idx) res = max(res, bit[idx]);
return res;
}
} feny, fenz;
void process()
{
cin >> n;
ys.pb(0);
zs.pb(0);
for (int i=1; i<=n; i++)
{
cin >> a[i][0] >> a[i][1] >> a[i][2];
ys.pb(a[i][1]);
zs.pb(a[i][2]);
}
sort(all(ys));
sort(all(zs));
compact(ys);
compact(zs);
for (int i=1; i<=n; i++) a[i][1] = lwb(all(ys), a[i][1]) - ys.bg(), a[i][2] = lwb(all(zs), a[i][2]) - zs.bg();
sort(range(a, 1, n));
int res = 0;
int y = 0, z = 0, j = 1;
//set<pii> s;
for (int i=1; i<=n; i++)
{
if (a[i][0] != a[i-1][0])
{
for (int k=j; k<i; k++)
{
int tmpz = feny.get(a[k][1] - 1);
int tmpy = fenz.get(a[k][2] - 1);
//cout << i << ' ' << k << ": " << a[k] << ' ' << tmpy << ' ' << tmpz << etr;
if (tmpz > a[k][2] && tmpz >= z && a[k][1] >= y)
{
y = a[k][1];
z = tmpz;
}
if (tmpy > a[k][1] && tmpy >= y && a[k][2] >= z)
{
y = tmpy;
z = a[k][2];
}
feny.update(a[k][1], a[k][2]);
fenz.update(a[k][2], a[k][1]);
}
j = i;
}
//cout << a[i] << ": " << y << ' ' << z << etr;
if (y > a[i][1] && z > a[i][2])
{
res = max(res, a[i][0] + ys[y] + zs[z]);
}
}
if (res == 0) cout << -1;
else cout << res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1; //cin >> t;
while (t--) process();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
team.cpp: In function 'void freop()':
team.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
team.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |