Submission #996859

#TimeUsernameProblemLanguageResultExecution timeMemory
996859modwweTeam Contest (JOI22_team)C++17
100 / 100
474 ms25632 KiB
#include<bits/stdc++.h> //#define int long long //#define ll long long #define down cout<<'\n'; #define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); #define modwwe int t;cin>>t; while(t--) #define bit(i,j) (i>>j&1) #define sobit(a) __builtin_popcountll(a) #define task "test" #define fin(x) freopen(x".inp","r",stdin) #define fou(x) freopen(x".out","w",stdout) #define pb push_back #define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms"; using namespace std; const int inf=1e9; void phongbeo(); const int mod2=1e9+7; const int mod1=998244353; struct icd { int a,b; }; struct ib { int a; int b; }; struct ic { int a,b,c; }; struct id { int a,b,c,d; }; struct ie { int a,b,c, d,e,f; }; int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l; int i,s10,s12; int el=29; main() { #ifndef ONLINE_JUDGE //fin(task),fou(task); #endif NHP /// cin>>s1; // modwwe phongbeo(),down checktime } int bit[450001]; void reset() { for(int i=1; i<=n*3; i++) bit[i]=3*n+1; } void upd(int x,int y) { for(x; x; x-=x&-x) bit[x]=min(bit[x],y); } int get(int x) { int ss=3*n+1; for(x; x<=n*3; x+=x&-x)ss=min(ss,bit[x]); return ss; } bool cmp(id a,id b) { if(a.a==b.a)return a.c>b.c; return a.a<b.a; } int d[150001]; id a[150001]; id b[150001]; vector<int> v; vector<int> v2[450001]; bool cmp2(id a,id b) { if(a.c==b.c)return a.a<b.a; return a.c>b.c; } void solve() { /// muc dich ham solve : /// sort theo ac /// aa dung cuoi /// ab dung giua /// ta co goi b1 b2 b3 la thu tu /// b1.a<b2.a<b3.a ///b1.c>b2.c>b3.c ///b1.b<b2.b>b3.b sort(a+1,a+1+n,cmp); for(int i=1;i<=n;i++) v2[a[i].c].clear(); reset(); for(int i=1; i<=n; i++) { l=a[i].c+1; r=n*3; s2=-1; while(l<=r) { int mid=l+r>>1; if(get(mid)<a[i].b)l=mid+1,s2=mid; else r=mid-1; } if(s2!=-1)d[a[i].d]=v[s2-1]+v[a[i].b-1], v2[s2].pb({a[i].d}); else d[a[i].d]=-1e9,upd(a[i].c,a[i].b); } sort(a+1,a+1+n,cmp2); reset(); for(int i=n; i>=1; --i) { //cout<<a[i].c,down upd(a[i].a,a[i].b); if(a[i-1].c!=a[i].c) for(auto x:v2[a[i-1].c]){ l=b[x].a+1; r=n*3; s2=-1; while(l<=r) { int mid=l+r>>1; if(get(mid)<b[x].b) l=mid+1,s2=mid; else r=mid-1; } if(s2!=-1) { s3=max(s3,d[x]+v[s2-1]); } } } /// cot chon thu 2 se la cot 2 va co cot 1 lon thu h2 } void phongbeo() { cin>>n; reset(); for(int i=1; i<=n; i++) cin>>a[i].a>>a[i].b>>a[i].c,a[i].d=i, v.pb(a[i].a), v.pb(a[i].b), v.pb(a[i].c); sort(v.begin(),v.end()); for(int i=1; i<=n; i++) a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1, a[i].b=lower_bound(v.begin(),v.end(),a[i].b)-v.begin()+1, a[i].c=lower_bound(v.begin(),v.end(),a[i].c)-v.begin()+1; s3=-1; for(int i=1;i<=n;i++) b[i]=a[i]; solve(); for(int i=1; i<=n; i++) swap(a[i].a,a[i].b), swap(b[i].a,b[i].b); solve(); for(int i=1; i<=n; i++) swap(a[i].a,a[i].b), swap(b[i].a,b[i].b); for(int i=1; i<=n; i++) swap(a[i].c,a[i].b), swap(b[i].c,b[i].b); solve(); cout<<s3; }

Compilation message (stderr)

team.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main()
      | ^~~~
team.cpp: In function 'void upd(int, int)':
team.cpp:62:9: warning: statement has no effect [-Wunused-value]
   62 |     for(x; x; x-=x&-x) bit[x]=min(bit[x],y);
      |         ^
team.cpp: In function 'int get(int)':
team.cpp:67:9: warning: statement has no effect [-Wunused-value]
   67 |     for(x; x<=n*3; x+=x&-x)ss=min(ss,bit[x]);
      |         ^
team.cpp: In function 'void solve()':
team.cpp:106:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  106 |             int mid=l+r>>1;
      |                     ~^~
team.cpp:127:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  127 |             int mid=l+r>>1;
      |                     ~^~
#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...