# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
587720 |
2022-07-02T09:25:13 Z |
Tekor |
Team Contest (JOI22_team) |
C++17 |
|
49 ms |
5432 KB |
#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],tekc;
ll t[N * 4],t1[N * 4];
vector <int> q;
void build(int v,int tl,int tr) {
t1[v] = LLINF;
if(tl == tr) {
t[v] = LLINF;
return;
}
int tm = (tl + tr) / 2;
build(v + v,tl,tm);
build(v + v + 1,tm + 1,tr);
t[v] = LLINF;
}
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]);
}
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]);
int lr = max(R + 1,p + 1);
while(lr <= k && get(1,1,k,lr,k) < max(c[pos],tekc)) {
R = lr;
tekc = max(tekc,c[pos]);
lr++;
}
lr = R + 1;
while(lr <= k && get(1,1,k,lr,k) < tekc) {
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
team.cpp: In function 'void solve()':
team.cpp:89:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for(int i = 1;i < q.size();i++) {
| ~~^~~~~~~~~~
team.cpp:97:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for(int i = 1;i < g.size();i++) {
| ~~^~~~~~~~~~
team.cpp:79:5: warning: unused variable 'mx' [-Wunused-variable]
79 | ll mx = 0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Incorrect |
49 ms |
5432 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Incorrect |
49 ms |
5432 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Incorrect |
49 ms |
5432 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Incorrect |
49 ms |
5432 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |