Submission #1047928

#TimeUsernameProblemLanguageResultExecution timeMemory
1047928modwweSequence (APIO23_sequence)C++17
100 / 100
606 ms51620 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; ib mer(ib a,ib b) { return {max(a.a,b.a),min(a.b,b.b)}; } struct IT { ib t[2000005]; int t2[2000005]; int t3[2000005]; 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; } 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; } if(t2[node]!=0||t3[node]!=0) 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; } if(t2[node]!=0||t3[node]!=0) 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]; if(t2[node]!=0||t3[node]!=0) 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)); } int walk(int node,int l,int r,int x,int y) { if(l==r) return l; int mid=l+r>>1; if(t2[node]!=0||t3[node]!=0) ff(node); if(t[node<<1].a-x>=0&&t[node<<1].b-y<=0) return walk(node<<1,l,mid,x,y); return walk(node<<1|1,mid+1,r,x,y); } } 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+1); s4=0; for(int i=1; i<=n; i++) { if(v[i].size()!=0){ v[i].pb(n+1); dem=0; 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,1,x,-1); ib xx=st.get(1,1,n+1,x,x2); st.upd2(1,1,n+1,1,x,1); s10=st.walk(1,1,n+1,xx.b,xx.a); dem++; s2=lower_bound(v[i].begin(),v[i].end(),s10)-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,1,x,-1); st.upd2(1,1,n+1,1,x,-1); }} } return s4; }

Compilation message (stderr)

sequence.cpp: In member function 'void IT::build(int, int, int)':
sequence.cpp:66:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 |         int mid=l+r>>1;
      |                 ~^~
sequence.cpp: In member function 'void IT::upd(int, int, int, int, int, int)':
sequence.cpp:95:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   95 |         int mid=l+r>>1;
      |                 ~^~
sequence.cpp: In member function 'void IT::upd2(int, int, int, int, int, int)':
sequence.cpp:111:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  111 |         int mid=l+r>>1;
      |                 ~^~
sequence.cpp: In member function 'ib IT::get(int, int, int, int, int)':
sequence.cpp:121:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  121 |         int mid=l+r>>1;
      |                 ~^~
sequence.cpp: In member function 'int IT::walk(int, int, int, int, int)':
sequence.cpp:127:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  127 |          int mid=l+r>>1;
      |                  ~^~
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:146:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  146 |         for(int j=0; j<v[i].size()-1; j++)
      |                      ~^~~~~~~~~~~~~~
sequence.cpp:158:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  158 |         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...