Submission #789215

#TimeUsernameProblemLanguageResultExecution timeMemory
7892151075508020060209tcSequence (APIO23_sequence)C++17
40 / 100
2059 ms48632 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int n; int oar[500005]; pair<pair<int,int>,int>sar[500005]; pair<pair<int,int>,int>tar[500005]; int ans; void slv(int l,int r){ if(l==r){return;} if(l>r){return;} int mi=(l+r)/2; slv(l,mi);slv(mi+1,r); int lmn=1e9; int lit=l;int rit=mi+1; for(int i=l;i<=r;i++){ if( ((rit==r+1)||(lit<=mi&&sar[lit].first.second<=sar[rit].first.second))){ tar[i]=sar[lit]; lmn=min(lmn,sar[lit].second); lit++; }else{ tar[i]=sar[rit]; ans=max(ans,sar[rit].second-lmn); rit++; } } for(int i=l;i<=r;i++){ sar[i]=tar[i]; } } int fslv(){ vector<pair<int,int>>vseq; map<int,int>frq; for(int i=1;i<=n;i++){ frq[oar[i]]++; } for(auto it=frq.begin();it!=frq.end();it++){ vseq.push_back({(*it).second,(*it).first}); }sort(vseq.begin(),vseq.end()); reverse(vseq.begin(),vseq.end()); ans=1; for(int j=0;j<vseq.size();j++){ int v=vseq[j].second; if(vseq[j].first<=ans){continue;} for(int i=0;i<=n;i++){ sar[i]=sar[max(i-1,0)]; if(oar[i]<v){ sar[i].first.first--; }else{ sar[i].first.first++; } if(oar[i]>v){ sar[i].first.second--; }else{ sar[i].first.second++; } if(oar[i]==v){ sar[i].second++; } } sort(sar+0,sar+n+1); slv(0,n); } return ans; } int sequence(int N, std::vector<int> A) { n=N; for(int i=0;i<n;i++){ oar[i+1]=A[i]; } return fslv(); return 0; } /* signed main() { cin>>n; for(int i=1;i<=n;i++){ cin>>oar[i]; } ans=1; for(int v=1;v<=3;v++){ for(int i=0;i<=n;i++){ sar[i]=sar[max(i-1,0)]; if(oar[i]<v){ sar[i].first.first--; }else{ sar[i].first.first++; } if(oar[i]>v){ sar[i].first.second--; }else{ sar[i].first.second++; } if(oar[i]==v){ sar[i].second++; } } sort(sar+0,sar+n+1); slv(0,n); } cout<<ans<<endl; return 0; } */

Compilation message (stderr)

sequence.cpp: In function 'int fslv()':
sequence.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int j=0;j<vseq.size();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...