Submission #1047721

#TimeUsernameProblemLanguageResultExecution timeMemory
1047721modwweSequence (APIO23_sequence)C++17
69 / 100
2071 ms54640 KiB
//https://www.instagram.com/_modwwe/ //#pragma GCC optimize("Ofast,unroll-loops") #include<bits/stdc++.h> //#define int long long //#define ll long long #define down cout<<'\n'; #define debug cout<<" cucuucucuuu",down #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; void phongbeo(); const int inf=1e9; const int mod2=1e9+7; const int mod1=998244353; struct icd { long double a; int 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; }; int n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,l,r,mid; int i,s10,s12; int kk; int el=29; /* main() { #ifndef ONLINE_JUDGE fin(task),fou(task); #endif NHP /// cin>>s1; // modwwe phongbeo(); }*/ struct IT { ib t[2000002]; int t2[2000002]; int t3[2000002]; void build(int node,int l,int r) { if(l==r) { t[node]= {n-l+1,n-l+1}; return; } int mid=l+r>>1; build(node<<1,l,mid); build(node<<1|1,mid+1,r); t[node]=mer(t[node<<1],t[node<<1|1]); } void ff(int x) { for(int i=x*2; i<=x*2+1; i++) t[i].a+=t2[x], t[i].b+=t2[x], t2[i]+=t2[x], t3[i]+=t3[x], t[i].a+=t3[x], t[i].b-=t3[x]; t2[x]=0; t3[x]=0; } ib mer(ib a,ib b) { return {max(a.a,b.a),min(a.b,b.b)}; } void upd(int node,int l,int r,int l1,int r1,int x) { if(l>r1||r<l1) return; if(l>=l1&&r<=r1) { t[node].a+=x; t[node].b+=x; t2[node]+=x; return; } ff(node); int mid=l+r>>1; upd(node<<1,l,mid,l1,r1,x); upd(node<<1|1,mid+1,r,l1,r1,x); t[node]=mer(t[node<<1],t[node<<1|1]); } void upd2(int node,int l,int r,int l1,int r1,int x) { if(l>r1||r<l1) return; if(l>=l1&&r<=r1) { t[node].a+=x; t[node].b-=x; t3[node]+=x; return; } ff(node); int mid=l+r>>1; upd2(node<<1,l,mid,l1,r1,x); upd2(node<<1|1,mid+1,r,l1,r1,x); t[node]=mer(t[node<<1],t[node<<1|1]); } ib get(int node,int l,int r,int l1,int r1) { if(l>r1||r<l1) return {-inf,inf}; if(l>=l1&&r<=r1) return t[node]; ff(node); int mid=l+r>>1; return mer(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1)); } } st; vector<int> v[500002]; int sequence(int x,vector<int>_a) { n=x; for(int i=0; i<x; i++) v[_a[i]].pb(i+1); st.build(1,1,n); for(int i=1; i<=n; i++) { dem=0; v[i].pb(n); for(int j=0;j<v[i].size()-1;j++) { int x=v[i][j]; int x2=v[i][j+1]; st.upd(1,1,n,1,x,-1); ib xx=st.get(1,1,n,x,x2); st.upd2(1,1,n,1,x,1); l=1; r=x; while(l<=r) { int mid=l+r>>1; ib xc=st.get(1,1,n,1,mid); if(xc.a-xx.b>=0&&xc.b-xx.a<=0)r=mid-1; else l=mid+1; } dem++; s2=lower_bound(v[i].begin(),v[i].end(),r+1)-v[i].begin(); s4=max(s4,dem-s2); } for(int j=0;j<v[i].size()-1;j++) { x=v[i][j]; st.upd(1,1,n,1,x,-1); st.upd2(1,1,n,1,x,-1); } } return s4; } /* void phongbeo() { cin>>n; vector<int> a(n); for(int i=0;i<n;i++) cin>>a[i]; cout<<sequence(n,a); }*/

Compilation message (stderr)

sequence.cpp: In member function 'void IT::build(int, int, int)':
sequence.cpp:74:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |         int mid=l+r>>1;
      |                 ~^~
sequence.cpp: In member function 'void IT::upd(int, int, int, int, int, int)':
sequence.cpp:106:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  106 |         int mid=l+r>>1;
      |                 ~^~
sequence.cpp: In member function 'void IT::upd2(int, int, int, int, int, int)':
sequence.cpp:122:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  122 |         int mid=l+r>>1;
      |                 ~^~
sequence.cpp: In member function 'ib IT::get(int, int, int, int, int)':
sequence.cpp:132:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  132 |         int mid=l+r>>1;
      |                 ~^~
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:147:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  147 |         for(int j=0;j<v[i].size()-1;j++)
      |                     ~^~~~~~~~~~~~~~
sequence.cpp:158:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  158 |                 int mid=l+r>>1;
      |                         ~^~
sequence.cpp:167:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  167 |         for(int j=0;j<v[i].size()-1;j++)
      |                     ~^~~~~~~~~~~~~~
#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...