版本比较
数列分块
正文
增加 18 行删除 18 行
182 行未改动全部展开18318418518618718718818919019151 行未改动24324424524624724724824925025120 行未改动27227327427527627627727827928028 行未改动30931031131231331331431531631711 行未改动32933033133233333333433533633723 行未改动36136236336436536536636736836965 行未改动43543643743843943944044144244390 行未改动53453553653753853853954054154271 行未改动61461561661761861861962062162282 行未改动70570670770870970971071171271399 行未改动81381481581681781781881982082124 行未改动84684784884985085085185285385432 行未改动88788888989089189289189289389489589689789889789889990090190290390390490590690790890991091091191291391412 行未改动182 行未改动全部展开 if (f == 0) change(l, r, d); else printf("%lld\n", a[r] + add[pos[r]]); } return 0;} }```
### [数列分块入门 2](https://loj.ac/p/6278)
51 行未改动 for (int i = p + 1; i <= q - 1; i++) add[i] += d; for (int i = l; i <= R[p]; i++) a[i] += d; for (int i = L[p]; i <= R[p]; i++) b[i] = a[i]; sort(b + L[p], 1 + b + R[p]); // 块内元素排序
for (int i = L[q]; i <= r; i++) a[i] += d; for (int i = L[q]; i <= R[q]; i++) b[i] = a[i]; sort(b + L[q], 1 + b + R[q]); // 块内元素排序 }20 行未改动 if (f == 0) change(l, r, d); else printf("%d\n", ask(l, r, d * d)); } return 0;} }```
### [数列分块入门 3](https://loj.ac/p/6279)
28 行未改动 for (int i = 1; i <= t; i++) { L[i] = (i - 1) * t + 1; R[i] = i * t; sort(b + L[i], 1 + b + R[i]);
} if (R[t] < n) t++, L[t] = R[t - 1] + 1, R[t] = n, sort(b + L[t], 1 + b + R[t]); for (int i = 1; i <= t; i++) { for (int j = L[i]; j <= R[i]; j++) {11 行未改动 for (int i = p + 1; i <= q - 1; i++) add[i] += d; for (int i = l; i <= R[p]; i++) a[i] += d; for (int i = L[p]; i <= R[p]; i++) b[i] = a[i]; sort(b + L[p], 1 + b + R[p]);
for (int i = L[q]; i <= r; i++) a[i] += d; for (int i = L[q]; i <= R[q]; i++) b[i] = a[i]; sort(b + L[q], 1 + b + R[q]); }23 行未改动 if (f == 0) change(l, r, d); else printf("%d\n", ask(l, r, d)); } return 0;} }```
### [数列分块入门 4](https://loj.ac/p/6280)
65 行未改动 if (f == 0) change(l, r, d); else printf("%lld\n", ask(l, r) % (d + 1)); } return 0;} }```
### [数列分块入门 5](https://loj.ac/p/6281)
90 行未改动 if (f == 0) change(l, r, d); else printf("%d\n", ask(l, r)); } return 0;} }```
### [数列分块入门 6](https://loj.ac/p/6282)
71 行未改动 if (f == 0) change(l, r); else query(r); } return 0;} }```
### [数列分块入门 7](https://loj.ac/p/6283)
82 行未改动 else if (f == 1) cmul(l, r, d); else printf("%lld\n", (a[r] * mul[pos[r]] % MOD + add[pos[r]]) % MOD); } return 0;} }```
### [数列分块入门 8](https://loj.ac/p/6284)
99 行未改动 scanf("%d %d %d", &l, &r, &d); printf("%d\n", ask(l, r, d)); } return 0;} }```
### [数列分块入门 9](https://loj.ac/p/6285)
24 行未改动using namespace std;int n, m, t, L[MAXN], R[MAXN], pos[MAXN];int a[MAXN], c[MAXN];int s[MAXN], dp[MAXX][MAXX]; // 存储 i ~ j 号块众数vector <int> p[MAXN]; // 储存当前元素是元素相同的第几个,以方便求区间内出现的次数 vector <int> p[MAXN]; // 储存当前元素是元素相同的第几个,以方便求区间内出现的次数
void init(int n) { t = sqrt(n * 1.0); for (int i = 1; i <= t; i++) {32 行未改动 } return ans1; } int ans1 = dp[p + 1][q - 1]; // 在 p + 1 ~ q - 1 这一序列中的众数 int ans2 = count(l, r, ans1); // 查找这个众数在区间里出现的个数 for (int i = l; i <= R[p]; i++) { // 暴力查找左边零散值每个数的数量 int ans2 = count(l, r, ans1); // 查找这个众数在区间里出现的个数 for (int i = l; i <= R[p]; i++) { // 暴力查找左边零散值每个数的数量 int t = count(l, r, a[i]); if (t == ans2) ans1 = min(ans1, a[i]); if (t > ans2) ans1 = a[i], ans2 = t; } for (int i = L[q]; i <= r; i++) { // 暴力查找右边零散值每个数的数量
for (int i = L[q]; i <= r; i++) { // 暴力查找右边零散值每个数的数量 int t = count(l, r, a[i]); if (t == ans2) ans1 = min(ans1, a[i]); if (t > ans2) ans1 = a[i], ans2 = t; }
return ans1;}
int main(){ scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); scanf("%d", &a[i]); c[i] = a[i]; } sort(c + 1, c + n + 1); int l = unique(c + 1, c + n + 1) - c - 1;12 行未改动