Submission #958116

#TimeUsernameProblemLanguageResultExecution timeMemory
958116zeta7532Sequence (APIO23_sequence)C++17
40 / 100
2050 ms57168 KiB
#include "sequence.h" #include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = int; const ll mod = 998244353; #define fi first #define se second #define rep(i,n) for(ll i=0;i<n;i++) #define all(x) x.begin(),x.end() #define faster ios::sync_with_stdio(false);cin.tie(nullptr) pair<int,int> f(pair<int,int> a,pair<int,int> b){ return {min(a.fi,b.fi),max(a.se,b.se)}; } template<typename T> struct RMQ{ const T INF={1LL<<30,-1LL<<30}; ll N; vector<T> dat; RMQ(ll N_):N(),dat(N_*4,INF){ ll x=1; while(N_>x) x*=2; N=x; } void update(ll i,int x){ i+=N-1; dat[i]={x,x}; while(i>0){ i=(i-1)/2; dat[i]=f(dat[i*2+1],dat[i*2+2]); } } T query(ll a,ll b){return query_sub(a,b,0,0,N);} T query_sub(ll a,ll b,ll k,ll l,ll r){ if(r<=a||b<=l){ return INF; }else if(a<=l&&r<=b){ return dat[k]; }else{ T vl=query_sub(a,b,k*2+1,l,(l+r)/2); T vr=query_sub(a,b,k*2+2,(l+r)/2,r); return f(vl,vr); } } }; int f(int N,vector<int> A){ vector<int> B=A; sort(all(B)); B.erase(unique(all(B)),B.end()); vector<int> C(N,1); vector<vector<int>> G(N+1); rep(i,N) G[A[i]].push_back(i); int ans=0; rep(i,B.size()){ RMQ<pair<int,int>> seg(N+1); vector<int> cum(N+1,0); rep(j,N) cum[j+1]=cum[j]+C[j]; rep(j,N+1) seg.update(j,cum[j]); int l=0,r=0; while(1){ if(r+1==G[B[i]].size()) break; auto e1=seg.query(0,G[B[i]][l]+1); auto e2=seg.query(G[B[i]][r+1]+1,N+1); if(e1.fi<=e2.se&&e2.fi<=e1.se){ r++; }else{ l++; } if(r<l) r++; ans=max(ans,r-l+1); } for(int j:G[B[i]]){ C[j]=-1; } } return ans; } int sequence(int N, std::vector<int> A) { int ans=0; vector<int> B=A; sort(all(B)); rep(j,2){ int cnt=0; rep(i,N) if(A[i]==B[(N-1+j)/2]) cnt++; ans=max(ans,cnt); } ans=max(ans,f(N,A)); rep(i,N) A[i]=N+1-A[i]; ans=max(ans,f(N,A)); return ans; }

Compilation message (stderr)

sequence.cpp: In function 'int f(int, std::vector<int>)':
sequence.cpp:11:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 | #define rep(i,n) for(ll i=0;i<n;i++)
......
   59 |     rep(i,B.size()){
      |         ~~~~~~~~~~            
sequence.cpp:59:5: note: in expansion of macro 'rep'
   59 |     rep(i,B.size()){
      |     ^~~
sequence.cpp:66:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             if(r+1==G[B[i]].size()) break;
      |                ~~~^~~~~~~~~~~~~~~~
#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...