Submission #919850

#TimeUsernameProblemLanguageResultExecution timeMemory
919850JakobZorzSequence (APIO23_sequence)C++17
60 / 100
1397 ms43904 KiB
#include"sequence.h" #include<vector> #include<iostream> using namespace std; const int TREE_SIZE=1<<19; int n; vector<int>arr[500000]; int tree_lazy[2*TREE_SIZE]; int tree_min[2*TREE_SIZE]; int tree_max[2*TREE_SIZE]; void push_lazy(int node){ if(tree_lazy[node]!=0){ tree_min[node]+=tree_lazy[node]; tree_max[node]+=tree_lazy[node]; if(node<TREE_SIZE){ tree_lazy[2*node]+=tree_lazy[node]; tree_lazy[2*node+1]+=tree_lazy[node]; } tree_lazy[node]=0; } } int get_min(int node,int rl,int rr,int l,int r){ push_lazy(node); if(r<=rl||rr<=l) return 1e8; if(l<=rl&&rr<=r) return tree_min[node]; int mid=(rl+rr)/2; return min(get_min(2*node,rl,mid,l,r),get_min(2*node+1,mid,rr,l,r)); } int get_max(int node,int rl,int rr,int l,int r){ push_lazy(node); if(r<=rl||rr<=l) return -1e8; if(l<=rl&&rr<=r) return tree_max[node]; int mid=(rl+rr)/2; return max(get_max(2*node,rl,mid,l,r),get_max(2*node+1,mid,rr,l,r)); } int get_min(int l,int r){ return get_min(1,0,TREE_SIZE,l,r); } int get_max(int l,int r){ return get_max(1,0,TREE_SIZE,l,r); } void add(int node,int rl,int rr,int l,int r,int v){ push_lazy(node); if(r<=rl||rr<=l) return; if(l<=rl&&rr<=r){ tree_lazy[node]+=v; push_lazy(node); return; } int mid=(rl+rr)/2; add(2*node,rl,mid,l,r,v); add(2*node+1,mid,rr,l,r,v); tree_min[node]=min(tree_min[2*node],tree_min[2*node+1]); tree_max[node]=max(tree_max[2*node],tree_max[2*node+1]); } void add(int l,int r,int v){ add(1,0,TREE_SIZE,l,r,v); } int sequence(int N,vector<int>A){ n=N; for(int i=0;i<n;i++) arr[A[i]-1].push_back(i); /*for(int i=0;i<=n;i++) tree[i]=-i;*/ for(int i=0;i<=n;i++) add(i,i+1,-i); int res=1; for(int v=0;v<n;v++){ for(int idx:arr[v]) /*for(int i=idx+1;i<=n;i++) tree[i]++;*/ add(idx+1,n+1,1); vector<int>mn1,mn2,mx1,mx2; for(int i:arr[v]){ mn1.push_back(get_min(0,i+1)); mn2.push_back(get_min(i,n+1)); mx1.push_back(get_max(0,i+1)); mx2.push_back(get_max(i,n+1)); } int l=0; for(int r=0;r<(int)arr[v].size();r++){ l=max(0,l-30); int min2=mn2[r]; int max2=mx2[r]; int min1=mn1[l]; int max1=mx1[l]; while(l<r&&(max1-l+1<min2-r||max2+r+1<min1+l)){ l++; min1=mn1[l]; max1=mx1[l]; } res=max(res,r-l+1); } for(int idx:arr[v]) /*for(int i=idx+1;i<=n;i++) tree[i]++;*/ add(idx+1,n+1,1); } return res; }
#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...