A11005 | Mister B and Astronomers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
After studying the beacons Mister B decided to visit alien's planet, because he learned that they live in a system of flickering star Moon. Moreover, Mister B learned that the star shines once in exactly $T$ seconds. The problem is that the star is yet to be discovered by scientists.
There are $n$ astronomers numerated from $1$ to $n$ trying to detect the star. They try to detect the star by sending requests to record the sky for $1$ second.
The astronomers send requests in cycle: the $i$ -th astronomer sends a request exactly $a_{i}$ second after the $(i-1)$ -th (i.e. if the previous request was sent at moment $t$ , then the next request is sent at moment $t+a_{i}$ ); the $1$ -st astronomer sends requests $a_{1}$ seconds later than the $n$ -th. The first astronomer sends his first request at moment $0$ .
Mister B doesn't know the first moment the star is going to shine, but it's obvious that all moments at which the star will shine are determined by the time of its shine moment in the interval $[0,T)$ . Moreover, this interval can be split into $T$ parts of $1$ second length each of form $[t,t+1)$ , where $t=0,1,2,...,(T-1)$ .
Mister B wants to know how lucky each astronomer can be in discovering the star first.
For each astronomer compute how many segments of form $[t,t+1)$ ( $t=0,1,2,...,(T-1)$ ) there are in the interval $[0,T)$ so that this astronomer is the first to discover the star if the first shine of the star happens in this time interval.
There are $n$ astronomers numerated from $1$ to $n$ trying to detect the star. They try to detect the star by sending requests to record the sky for $1$ second.
The astronomers send requests in cycle: the $i$ -th astronomer sends a request exactly $a_{i}$ second after the $(i-1)$ -th (i.e. if the previous request was sent at moment $t$ , then the next request is sent at moment $t+a_{i}$ ); the $1$ -st astronomer sends requests $a_{1}$ seconds later than the $n$ -th. The first astronomer sends his first request at moment $0$ .
Mister B doesn't know the first moment the star is going to shine, but it's obvious that all moments at which the star will shine are determined by the time of its shine moment in the interval $[0,T)$ . Moreover, this interval can be split into $T$ parts of $1$ second length each of form $[t,t+1)$ , where $t=0,1,2,...,(T-1)$ .
Mister B wants to know how lucky each astronomer can be in discovering the star first.
For each astronomer compute how many segments of form $[t,t+1)$ ( $t=0,1,2,...,(T-1)$ ) there are in the interval $[0,T)$ so that this astronomer is the first to discover the star if the first shine of the star happens in this time interval.
输入格式
The first line contains two integers $T$ and $n$ ( $1<=T<=10^{9}$ , $2<=n<=2·10^{5}$ ).
The second line contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=10^{9}$ ).
The second line contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=10^{9}$ ).
输出格式
Print $n$ integers: for each astronomer print the number of time segments describer earlier.
输入输出样例
输入 #1
4 2 2 3
输出 #1
3 1
输入 #2
5 4 1 1 1 1
输出 #2
2 1 1 1
In the first sample test the first astronomer will send requests at moments $t_{1}=0,5,10,...$ , the second — at moments $t_{2}=3,8,13,...$ . That's why interval $[0,1)$ the first astronomer will discover first at moment $t_{1}=0$ , $[1,2)$ — the first astronomer at moment $t_{1}=5$ , $[2,3)$ — the first astronomer at moment $t_{1}=10$ , and $[3,4)$ — the second astronomer at moment $t_{2}=3$ .
In the second sample test interval $[0,1)$ — the first astronomer will discover first, $[1,2)$ — the second astronomer, $[2,3)$ — the third astronomer, $[3,4)$ — the fourth astronomer, $[4,5)$ — the first astronomer.
In the second sample test interval $[0,1)$ — the first astronomer will discover first, $[1,2)$ — the second astronomer, $[2,3)$ — the third astronomer, $[3,4)$ — the fourth astronomer, $[4,5)$ — the first astronomer.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted