版本比较
数论分块
正文
增加 9 行删除 9 行
2 行未改动3456778910111213141415161718155 行未改动全部展开17417517617717817817918018118210 行未改动1931941951961971971981992002012002012022032042052042052062072082092102102112122132142152 行未改动[ds记录](https://chat.baidu.com/search?isShowHello=1&replace=1&extParams=%7B%22ori_lid%22%3A%229568001704947815586%22%2C%22enter_type%22%3A%22sidebar_dialog%22%2C%22subEnterType%22%3A%22his_middle%22%2C%22forceRefresh%22%3A1765245556603%7D):::## 数论分块::::success[1.基础概念:]> oi wiki: > oi wiki:> 数论分块可以快速计算一些形如>$$>\sum_{i=1}^{n}f(i)g(⌊(n/i)⌋)>$$>的和式
其中,f(i)代表的是每个$i$对应的权重(通常为1),而g则是一个可以将值映射为其他数值的函数(如n/i -> n%i). 其中,f(i)代表的是每个$i$对应的权重(通常为1),而g则是一个可以将值映射为其他数值的函数(如n/i -> n%i).至于g中是$⌊(n/i)⌋$,是因为这样才可以用分块快速处理
>所有分块变种都遵循相似的基本流程:>1. 初始化:左端点$l=1$155 行未改动全部展开 while(l<=min(a,k)){ r=(k/(k/l)); if(r>a)r=a; int nl=k%l,nr=k%r; ans+=(r-l+1)*(nl+nr)/2; ans+=(r-l+1)*(nl+nr)/2; l=r+1; } cout<<ans<<endl;}10 行未改动 damage to it, and also spreads to the left (towards decreasing i) and to the right (towards increasing i) to alive monsters, dealing k damage to each. When the lightning reaches a dead monster or the beginning/end of the row, it stops. A monster is considered alive if its health points are strictly greater than 0.
For each k from 1 to $max(a_1,a_2,…,a_n)$,calculate the minimum number of seconds it takes to kill all the monsters.::::info[形式化题意]There are n numbers,namely $a_1,a_2,\dots,a_n$ Every second, you can choose a continueous positive sequence and decrease the $a_i$ in the sequence by one. There are n numbers,namely $a_1,a_2,\dots,a_n$Every second, you can choose a continueous positive sequence and decrease the $a_i$ in the sequence by one.what is the minimum number of seconds to make the sequence non-positive
:::align{right} [中文](https://www.luogu.com.cn/problem/CF1954E) :::align{right}[中文](https://www.luogu.com.cn/problem/CF1954E):::::::
::::success[解法]显然,最小时间和顺序无关,于是可以推出$\sum_{i=1}^n c_i * ⌈\frac{a_i}{k}⌉$,用整除分块优化即可。 显然,最小时间和顺序无关,于是可以推出$\sum_{i=1}^n c_i * ⌈\frac{a_i}{k}⌉$,用整除分块优化即可。其中$c_i$表示:
* 如果$i=1$或$a_i\geq a_{i-1}$,则将$c_i+1$* 如果$i=n$或$a_i< a_{i+1}$,则将$c_i-1$::::