省流:差分前缀和。
Solution
是的,你没看错,这道题就是到普及组内容的差分前缀和!我们用 表示第 位有几个 ,然后跑一遍高位移位就结束了。
但为什么我还吃了一发罚时呢?因为我们 存的是第 位前缀和,但 是可以大于 的,而且可以非常大,所以你的数组开 会炸掉!
所以 严格大于 。
Code
#include<bits/stdc++.h>
#define int long long
namespace FastIO{
template<typename T>inline void read(T &x){
x=0;int f=1;char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);x*=f;
}
template<typename T,typename...Args>
inline void read(T &x,Args&...args){
read(x);
read(args...);
}
template<typename T>void print(T x){
if(x<0)x=-x,putchar('-');
if(x>9)print(x/10);
putchar(x%10^48);
}
}
using namespace FastIO;
using namespace std;
const int N=2e7+5;
int n,a[N],ans[N],mx;
signed main(){
read(n);
for(int i=1;i<=n;i++){
read(a[i]);
ans[1]++;
ans[a[i]+1]--;
mx=max(mx,a[i]);
}
for(int i=1;i<=mx+1;i++){
ans[i]+=ans[i-1];
}
int i=1;
while(true){
if(ans[i]>9){
int x=(ans[i]-ans[i]%10)/10;
ans[i+1]+=x;
ans[i]=ans[i]%10;
}
i++;
if(ans[i]<=0)break;
}
for(int j=i-1;j>=1;j--){
print(ans[j]);
}
}