Time limit : 2sec / Memory limit : 256MB
Problem Statement
Snuke got an integer sequence from his mother, as a birthday present. The sequence has $N$ elements, and the $i$-th of them is $i$. Snuke performs the following $Q$ operations on this sequence. The $i$-th operation, described by a parameter $q_i$, is as follows:
- Take the first $q_i$ elements from the sequence obtained by concatenating infinitely many copy of the current sequence, then replace the current sequence with those $q_i$ elements.
After these $Q$ operations, find how many times each of the integers $1$ through $N$ appears in the final sequence.
Constraints
- $1≦N≦10^5$
- $0≦Q≦10^5$
- $1≦qi≦10^18$
All input values are integers.
Input
The input is given from Standard Input in the following format:
$N\;Q$
$q_1$
$…$
$q_Q$
Output
Print N lines. The i-th line (1≦$i$≦$N$) should contain the number of times integer $i$ appears in the final sequence after the $Q$ operations.
Sample Input 1
|
|
Sample Output 1
|
|
Sample Input 2
|
|
Sample Output 2
|
|
题意
有一个数字串S,初始长度为n,是1 2 3 4 …… n。
有m次操作,每次操作给你一个正整数a[i],你先把S无穷重复,然后把前a[i]截取出来成为新的S。
求m次操作后,每个数字在S中出现的次数。
分析
发现如果$ai≤a_{i+1}$那么$a_i$是无效的,把序列变成严格上升的
然后令f[i]为第i次操作后的序列在最终序列中出现多少次,有f[m]=1
整块整块的直接相乘
如果有边角料,可以发现,长为x边角料与序列前x是相等的
而所有序列除该位不存在以外,前x位都是相等的($a_i$序列严格上升
那就找到一个最大的小于等于x的$a_i$,对f[i]产生贡献,再用同样方式处理边角料
最后x<n
存s[x]表示序列1-i
在最终序列出现多少次
CODE
ps:中途变量混乱,n
m
num
难以分清