标签:tin problem print pos ota void lis har fine
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 13448 | Accepted: 8559 |
Description
Input
Output
Sample Input
5 1 2 1 0
Sample Output
2 4 5 3 1
Source
从后往前考虑,如果第\(k\)头牛前面有\(A_k\)头比它矮,那么它的身高\(H_k\)是数值\(1\sim n\)中第\(A_k+1\)小没有在\(\{H_{k+1},H_{k+2},\dots,H_n\}\)中出现的数。
那么用01树状数组维护,每次倍增求第\(A_k+1\)小的就行了。
时间复杂度\(O(n \log n)\),USACO的数据是真的弱,n才8000。
#include<iostream>
#include<cmath>
#define rg register
#define il inline
#define co const
template<class T>il T read(){
rg T data=0,w=1;rg char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') w=-1;ch=getchar();}
while(isdigit(ch)) data=data*10+ch-'0',ch=getchar();
return data*w;
}
template<class T>il T read(rg T&x) {return x=read<T>();}
typedef long long ll;
co int N=8e3+1;
int n,t,a[N],c[N],h[N],p[14];
void add(int x){
while(x<=n) --c[x],x+=x&-x;
}
int main(){
// freopen(".in","r",stdin),freopen(".out","w",stdout);
p[0]=1;
for(int i=1;i<14;++i) p[i]=p[i-1]<<1;
t=log((float)read(n))/log(2.0);
for(int i=1;i<=n;++i){
++c[i];
if(i+(i&-i)<=n) c[i+(i&-i)]+=c[i];
}
a[1]=1;
for(int i=2;i<=n;++i) a[i]=read<int>()+1;
for(int i=n,ans,sum;i;--i){
ans=sum=0;
for(int j=t;j>=0;--j)
if(ans+p[j]<=n&&sum+c[ans+p[j]]<a[i])
sum+=c[ans+p[j]],ans+=p[j];
add(h[i]=ans+1);
}
for(int i=1;i<=n;++i) printf("%d\n",h[i]);
return 0;
}
标签:tin problem print pos ota void lis har fine
原文地址:https://www.cnblogs.com/autoint/p/10588200.html