正文
增加 9 行删除 9 行
6 行未改动789101112131415161729 行未改动47484950515253545517 行未改动737475767778798081826 行未改动### 具体实现1. 初始化,输入并离线2. **莫队的精髓**,选择合适的排序方式:朴素的,直接按左端点所在块为第一关键字,右端点为第二关键字,每个块最多指针跳动 $2\times n$ 次,共有 $\sqrt n$ 个块,总复杂度 $O(n\times \sqrt{n})$。第二种,奇偶性。考虑多出的一倍无效回跳,奇偶性排序,降低 $2$ 的常数。或者莫名其妙写错了,有时候也会很快。3. 指针跳动,在常数允许的情况下直接定义函数 `inline void add(int val)` 和 `inline void del(int val)` 更新答案,便于书写。29 行未改动inline void add(int x){cnt[x]++;if (cnt[x]%2) ans++;else ans--;}inline void dele(int x){cnt[x]++;17 行未改动for (int i=1;i<=Q;i++) cout<<ANS[i]<<'\n';return 0;}```多倍经验:[P3901](https://www.luogu.com.cn/problem/P3901),纯板子。[P2709](https://www.luogu.com.cn/problem/P2709),维护平方和。[P1494](https://www.luogu.com.cn/problem/P3901),套个组合数推式子。[P3709](https://www.luogu.com.cn/problem/P3709)&[P1997](https://www.luogu.com.cn/problem/P1997),区间众数。[P4867](https://www.luogu.com.cn/problem/P4867)&[P4396](https://www.luogu.com.cn/problem/P4396),套权值线段树/值域分块。6 行未改动789101112131415161729 行未改动47484950515253545517 行未改动737475767778798081826 行未改动### 具体实现1. 初始化,输入并离线2. **莫队的精髓**,选择合适的排序方式:朴素的,直接按左端点所在块为第一关键字,右端点为第二关键字,每个块最多指针跳动 $2\times n$ 次,共有 $\sqrt n$ 个块,总复杂度 $O(n\times \sqrt{n})$。第二种,奇偶性。考虑多出的一倍无效回跳,奇偶性排序,降低 $2$ 的常数。或者莫名其妙写错了,有时候也会很快。3. 指针跳动,在常数允许的情况下直接定义函数 `inline void add(int val)` 和 `inline void del(int val)` 更新答案,便于书写。29 行未改动inline void add(int x){cnt[x]++;if (cnt[x]%2) ans++;else ans--;}inline void dele(int x){cnt[x]++;17 行未改动for (int i=1;i<=Q;i++) cout<<ANS[i]<<'\n';return 0;}```多倍经验:[P3901](https://www.luogu.com.cn/problem/P3901),纯板子。[P2709](https://www.luogu.com.cn/problem/P2709),维护平方和。[P1494](https://www.luogu.com.cn/problem/P3901),套个组合数推式子。[P3709](https://www.luogu.com.cn/problem/P3709)&[P1997](https://www.luogu.com.cn/problem/P1997),区间众数。[P4867](https://www.luogu.com.cn/problem/P4867)&[P4396](https://www.luogu.com.cn/problem/P4396),套权值线段树/值域分块。