~{→看不见LaTex格式的Dalao们请刷新本页Thanks♪(・ω・)ノ←}~
2019寒假集训题
E.Snuke Line
题面
Snuke has decided to play a game, where the player runs a railway company. There are $M+1$ stations on Snuke Line, numbered $0$ through $M$. A train on Snuke Line stops at station $0$ and every $d$-th station thereafter, where $d$ is a predetermined constant for each train. For example, if $d=3$, the train stops at station $0, 3, 6, 9$, and so forth.
There are $N$ kinds of souvenirs sold in areas around Snuke Line. The $i$-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations $l_i,l_i+1,l_i+2,…r_i$.
There are M values of d, the interval between two stops, for trains on Snuke Line: $1, 2, 3, …, M$. For each of these $M$ values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station $0$. Here, assume that it is not allowed to change trains.
简要翻译
有$m$个点集,第$i$个点集包含$0$至$m$中编号是$i$的倍数的点。
给定$n$个区间,对于每个点集,求出有多少个区间包含点集内的至少一个点。
或者说是:
有$n$个区间,现在询问你对于$1\le i\le m$的每个$i$,有多少个区间至少包含一个$i$的倍数?
Input
输入的标准格式如下:
1 | N M |
Output
输出答案$M$行。第$i$-th行包含停在$d$站的答案。
Sample Input 1
3 3
1 2
2 3
3 3
Sample Output 1
3
2
2
Sample Input 2
7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4
Sample Output 2
7
6
6
5
4
5
5
3
2
Hint
$1\le M\le 10^5$
$1\le N\le 3×10^5$
$1\le l_i\le r_i\le M$
我们如果按题目去题意去做,我也不知道怎么想。
我们反着思考,如果一个区间中没有$i$的倍数,那么它一定是被相邻的两个$i$的倍数夹在中间了,或是在最大的$i$的倍数的右边了。
所以我们可以先读入所有的数据再用可持久化线段树离线处理啦!
Code
1 |
|