# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
917518 |
2024-01-28T11:19:09 Z |
_VIBE |
Team Contest (JOI22_team) |
C++17 |
|
2000 ms |
16568 KB |
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
void Excuse_Me(int TC)
{
int n;
cin>>n;
vector<vector<int>> g(n);
vector<int> v;
for(int i=0;i<n;i++){
int a,b,c;
cin>>a>>b>>c;
g[i]={a,b,c};
v.push_back(b);
v.push_back(b-1);
v.push_back(b+1);
}
sort(g.begin(),g.end());
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
int m=v.size();
map<int,int> comp;
for(int i=0;i<v.size();i++) comp[v[i]]=i;
int mn[4*m],mx[4*m];
function<void(int,int,int)> build=[&](int s,int e,int i)->void{
if(s==e){
mn[i]=1e18;
mx[i]=-1e18;
return;
}
int m=(s+e)/2;
build(s,m,i*2);
build(m+1,e,i*2+1);
mn[i]=min(mn[i*2],mn[i*2+1]);
mx[i]=max(mx[i*2],mx[i*2+1]);
};
build(0,m-1,1);
vector<pair<int,int>> p;
int ans=-1;
function<void(int,int,int,int,int)> update=[&](int s,int e,int i,int pos,int val)->void{
if(s==e){
mn[i]=min(mn[i],val);
mx[i]=max(mx[i],val);
return;
}
int m=(s+e)/2;
if(pos<=m) update(s,m,i*2,pos,val);
else update(m+1,e,i*2+1,pos,val);
mn[i]=min(mn[i*2],mn[i*2+1]);
mx[i]=max(mx[i*2],mx[i*2+1]);
};
function<int(int,int,int,int,int,bool)> get=[&](int s,int e,int i,int l,int r,bool ismax)->int{
if(l>r) return (ismax?(-1e18):(1e18));
if(s==l and r==e) return (ismax?mx[i]:mn[i]);
int m=(s+e)/2;
if(ismax) return max(get(s,m,i*2,l,min(m,r),ismax),get(m+1,e,i*2+1,max(m+1,l),r,ismax));
return min(get(s,m,i*2,l,min(m,r),ismax),get(m+1,e,i*2+1,max(m+1,l),r,ismax));
};
for(int i=0;i<n;i++){
for(auto x:p){
if(x.first>g[i][1] and x.second>g[i][2]) ans=max(ans,g[i][0]+x.first+x.second);
}
int b=g[i][1];
int c=g[i][2];
//taking this b as max
// then i have to find max c in range 0,comp[b-1]
//if this c is greater than my current c then i can take that pair
int max_c=get(0,m-1,1,0,comp[b-1],true);
if(max_c>c) p.push_back({b,max_c});
//now my b will act as min and i have to find greatest index in range comp[b+1],m-1 such that its value is less than my current c
int low=comp[b+1],high=m-1;
int ind=-1;
while(low<=high){
int mi=(low+high)/2;
// find if min_c from range [mi,m-1] is less than my current_c
int min_c=get(0,m-1,1,mi,m-1,false);
if(min_c<c){
ind=mi;
low=mi+1;
}
else{
high=mi-1;
}
}
if(ind!=-1) p.push_back({v[ind],c});
update(0,m-1,1,comp[b],c);
}
cout<<ans;
}
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
freopen("error.txt","w",stderr);
int Tc=1;
// cin>>Tc;
for(int tc=1;tc<=Tc;tc++)
{
Excuse_Me(tc);
}
return 0;
}
Compilation message
team.cpp: In function 'void Excuse_Me(long long int)':
team.cpp:37:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<v.size();i++) comp[v[i]]=i;
| ~^~~~~~~~~
team.cpp: In function 'int main()':
team.cpp:153:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
153 | freopen("error.txt","w",stderr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
1112 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
1112 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Execution timed out |
2077 ms |
16568 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Execution timed out |
2077 ms |
16568 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Execution timed out |
2077 ms |
16568 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Execution timed out |
2077 ms |
16568 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
1112 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |