版本比较
分块&莫队
正文
增加 6 行删除 6 行
6 行未改动7891011111213141516171819181920212122232425235 行未改动全部展开2612622632642652652662672682692 行未改动27227327427527627627727827928015 行未改动6 行未改动$$a+b\ge 2\sqrt {ab}$$### 前置.前置.2 基本不等式的证明$\because(a-b)^2\ge 0\\\therefore a^2+b^2-2ab\ge0\\\therefore a^2+b^2\ge 2ab\\\therefore a^2+b^2+2ab\ge4ab\\\therefore (a+b)^2\ge 4ab\\\therefore a+b\ge 2\sqrt {ab}$### 前置.前置.3 基本不等式求最值形象的,当 $a=b$ 时,$a+b$ 取得最小值 $2\sqrt {ab}$。 形象的,当 $a=b$ 时,$a+b$ 取得最小值 $2\sqrt {ab}$。## 前置.1 分块将一个序列分成几块,如果能在较优的时间复杂度预处理/修改这些块,并在较优的时间复杂度中完成查询这些块,就可以使用分块算法。
比如这道题:
> [P3372 【模板】线段树 1(分块)](https://www.luogu.com.cn/problem/P3372)> > >>> 维护一个序列的两种操作:> >> 1. 求区间 $[l,r]$ 的和。> 2. 为区间 $[l,r]$ 加上 $x$。
分块,就是将一个区间操作转化成一些散块和一些整块操作。235 行未改动全部展开 { cnt[k.y]--; cnt[k.x]++; if(cnt[k.y]==0) Count--; if(cnt[k.x]==1) Count++; if(cnt[k.x]==1) Count++; } a[k.w]=k.x;}void delTime(int t){2 行未改动 { cnt[k.x]--; cnt[k.y]++; if(cnt[k.x]==0) Count--; if(cnt[k.y]==1) Count++; if(cnt[k.y]==1) Count++; } a[k.w]=k.y;}```15 行未改动