제출 #930244

#제출 시각아이디문제언어결과실행 시간메모리
930244Wansur서열 (APIO23_sequence)C++17
100 / 100
884 ms49860 KiB
#include <bits/stdc++.h> #define f first #define s second #define ent '\n' using namespace std; typedef long long ll; const int mxn=5e5+12; const int mod=998244353; vector<int> g[mxn]; int p[mxn*4]; int mn[mxn*4]; int mx[mxn*4]; void build(int v,int tl,int tr){ p[v]=0; if(tl==tr){ mn[v]=mx[v]=tl; } else{ int mid=tl+tr>>1; build(v*2,tl,mid); build(v*2+1,mid+1,tr); mn[v]=min(mn[v*2],mn[v*2+1]); mx[v]=max(mx[v*2],mx[v*2+1]); } } void push(int v,int tl,int tr){ if(tl==tr){ return; } mn[v*2]+=p[v]; mn[v*2+1]+=p[v]; p[v*2]+=p[v]; p[v*2+1]+=p[v]; mx[v*2]+=p[v]; mx[v*2+1]+=p[v]; p[v]=0; } void upd(int v,int tl,int tr,int l,int r,int x){ push(v,tl,tr); if(tl>r || l>tr)return; if(tl>=l && tr<=r){ mn[v]+=x; mx[v]+=x; p[v]+=x; return; } int mid=tl+tr>>1; upd(v*2,tl,mid,l,r,x); upd(v*2+1,mid+1,tr,l,r,x); mn[v]=min(mn[v*2],mn[v*2+1]); mx[v]=max(mx[v*2],mx[v*2+1]); } pair<int,int> get(int v,int tl,int tr,int l,int r){ push(v,tl,tr); if(tl>r || l>tr)return {1e9,-1e9}; if(tl>=l && tr<=r){ return {mn[v],mx[v]}; } int mid=tl+tr>>1; pair<int,int> x=get(v*2,tl,mid,l,r),y=get(v*2+1,mid+1,tr,l,r); return {min(x.f,y.f),max(x.s,y.s)}; } int sequence(int n, std::vector<int> A){ reverse(A.begin(),A.end()); vector<int> a={0}; for(int x:A){ a.push_back(x); } for(int i=1;i<=n;i++){ g[a[i]].push_back(i); } for(int i=1;i<=n;i++){ upd(1,0,n,i,n,1); } int ans=1; for(int x=1;x<=n;x++){ /*for(int i=0;i<g[x].size();i++){ int l=g[x][i]; pair<int,int> L=get(1,0,n,0,l-1); while(i+ans<g[x].size()){ int r=g[x][i+ans]; pair<int,int> R=get(1,0,n,r,n); R.f-=(ans+1)*2; if(max(L.f,R.f)<=min(L.s,R.s)){ ans++; } else break; } upd(1,0,n,l,n,-2); } continue;*/ for(int i:g[x]){ upd(1,0,n,i,n,-2); } for(int i=g[x].size()-1;i>=0;i--){ int l=g[x][i]; upd(1,0,n,l,n,2); pair<int,int> L=get(1,0,n,0,l-1); while(i+ans<g[x].size()){ int r=g[x][i+ans]; pair<int,int> R=get(1,0,n,r,n); R.f-=(ans+1)*2; if(max(L.f,R.f)<=min(L.s,R.s)){ ans++; } else break; } } for(int i:g[x]){ upd(1,0,n,i,n,-2); } } return ans; }

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

sequence.cpp: In function 'void build(int, int, int)':
sequence.cpp:22:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |   int mid=tl+tr>>1;
      |           ~~^~~
sequence.cpp: In function 'void upd(int, int, int, int, int, int)':
sequence.cpp:52:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |  int mid=tl+tr>>1;
      |          ~~^~~
sequence.cpp: In function 'std::pair<int, int> get(int, int, int, int, int)':
sequence.cpp:65:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |  int mid=tl+tr>>1;
      |          ~~^~~
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:106:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |    while(i+ans<g[x].size()){
      |          ~~~~~^~~~~~~~~~~~
#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...