제출 #981638

#제출 시각아이디문제언어결과실행 시간메모리
9816388pete8서열 (APIO23_sequence)C++17
35 / 100
218 ms13776 KiB
#include "sequence.h" #include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<limits.h> #include <cassert> #include<cmath> #include<set> #include<algorithm> #include <iomanip> #include<numeric> //gcd(a,b) #include<bitset> #include <cstdlib> #include <cstdint> using namespace std; #define ll long long #define f first //#define endl "\n" #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define vi vector<int> #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; const int mxn=5e5,lg=24; int mx=0; struct fen{ //using fenwick cus i dont wanna write slding median int fwk[mxn+10]; vector<pii>keep; void update(int pos,int val){ keep.pb({pos,val}); for(int i=pos;i<=mx;i+=(i&-i))fwk[i]+=val; } int qry(int pos){ if(pos<0)return 0; int sum=0; for(int i=pos;i>0;i-=(i&-i))sum+=fwk[i]; return sum; } void re(){ for(auto i:keep)for(int j=i.f;j<=mx;j+=(j&-j))fwk[j]-=i.s; keep.clear(); } int get(int x){ x++; int pos=0,sum=0; for(int i=lg;i>=0;i--){ if(pos+(1LL<<i)<=mx&&fwk[pos+(1LL<<i)]+sum<x){ pos+=(1LL<<i); sum+=fwk[pos]; } } return pos+1; } }t; int cnt[mxn+10],r[mxn+10],l[mxn+10]; int sequence(int n, vector<int>v){ int ans=0; if(n>2e3){ //sub 3 case get l,r or get l-> other side for(auto i:v)cnt[i]++,l[i]=n+1; for(int i=0;i<n;i++)r[v[i]]=max(r[v[i]],i),l[v[i]]=min(l[v[i]],i); for(int i=0;i<n;i++){ int cur=i; while(cur<v.size()&&v[cur]==v[i])cur++; ans=max(ans,cur-i);//take range l,r i=cur-1; } for(auto i:v){//take l->r int other=n-(r[i]-l[i]+1); if(other+cnt[i]>=(n/2)+1)ans=max(ans,cnt[i]); } return ans; } for(auto i:v)mx=max(mx,i); auto bru=[&](int x){ int a=t.get(x); return t.qry(a)-t.qry(a-1); }; for(int i=0;i<n;i++){ t.re(); for(int j=i;j<n;j++){ t.update(v[j],1); int x1=(j-i)/2,x2=ceil((j-i)*1.0/2*1.0); ans=max({ans,bru(x1),bru(x2)}); } } if(ans==0)assert(0); return ans; } /* int32_t main(){ int n;cin>>n; vector<int>v(n); for(int i=0;i<n;i++)cin>>v[i]; cout<<sequence(n,v); }*/ /* 9 1 1 1 2 2 3 2 2 1 */ /* constraint of being a medain A number of number <x,B number of number >x,C number of number ==x if C>=A+B if A+C>=B && C<=A+B if A+B>=c && B<=A+C i might be wrong */

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:79:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |       while(cur<v.size()&&v[cur]==v[i])cur++;
      |             ~~~^~~~~~~~~
#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...