版本比较
数列分块入门
正文
增加 14 行删除 14 行
4 行未改动5678991011121360 行未改动7475767778787980818282 行未改动16516616716816916917017117217370 行未改动24424524624724824824925025025125225325425525625725725825925926026126226312 行未改动2762772782792802802812822832842852862872882892892902912922932932942952962972982992982993003013023032 行未改动30630730830931031031131231231331431531620 行未改动4 行未改动#### [数据结构 Part III](https://www.luogu.com.cn/training/294973)主要是一些更暴力的数据结构,例如分块,莫队等。
---### [数列分块入门1~9](https://loj.ac/p?tagIds=10%2C207) ### [数列分块入门1~9](https://loj.ac/p?tagIds=10%2C207)以下用这几道题来熟悉分块,从线段树到蒲公英。
60 行未改动记录一个块内是否全为 $0$ 或 $1$,如果是就跳过。
#### [AC记录](https://loj.ac/s/1734380)
### 多倍经验 ### 多倍经验- [P4145 上帝造题的七分钟 2 / 花神游历各国](https://www.luogu.com.cn/problem/P4145)- [SP2713 GSS4 - Can you answer these queries IV](https://www.luogu.com.cn/problem/SP2713)- [CF438D The Child and Sequence](https://www.luogu.com.cn/problem/CF438D)- [CF920F SUM and REPLACE](https://www.luogu.com.cn/problem/CF920F)82 行未改动整块的统计完了,询问只要相减,那怎么处理处理散块?
~~你傻啊,~~ 散块暴力统计也能在 $\mathcal{O}(\sqrt{n})$ 之内完成!
这样就能算出 $[l+1,r-1]$ 之间的 $a_i$ 的出现次数就是 `cnt[a[i]]+s[belong[r]-1][a[i]]-s[belong[l]][a[i]]`(`cnt` 就是暴力统计的数组),这样就以 $\mathcal{O}(\dfrac{n^2}{T})$ 的空间复杂度换来最优时 $\mathcal{O}(n\sqrt{n})$ 的时间复杂度。 这样就能算出 $[l+1,r-1]$ 之间的 $a_i$ 的出现次数就是 `cnt[a[i]]+s[belong[r]-1][a[i]]-s[belong[l]][a[i]]`(`cnt` 就是暴力统计的数组),这样就以 $\mathcal{O}(\dfrac{n^2}{T})$ 的空间复杂度换来最优时 $\mathcal{O}(n\sqrt{n})$ 的时间复杂度。
更多细节详见代码。
#### [AC记录2](https://loj.ac/s/1734834) 时间复杂度 $\mathcal{O}(\dfrac{n^2}{T}+qT)$ 空间复杂度 $\mathcal{O}(\dfrac{n^2}{T})$70 行未改动#endif#define putchar writecharinline int read() { int c=readchar(),x=0; while(c<=32) while(c<=32) c=readchar(); for(; ('0'<=c && c<='9'); c=readchar()) for(; ('0'<=c && c<='9'); c=readchar()) x=x*10+c-'0'; return x;}inline void write(int x) { char s[25]; int n=0; while(x || !n) while(x || !n) s[n++]='0'+x%10,x/=10; while(n--) while(n--) writechar(s[n]);}
int n,q;12 行未改动 a[i]=lower_bound(b+1,b+len+1,a[i])-b; pre[i]=v[a[i]].size(); v[a[i]].push_back(i); }
block=ceil(pow(n,0.46)); tot=n/block; if(n%block) ++tot; for(int i=1;i<=n;i++) belong[i]=((i-1)/block)+1; for(int i=1;i<=tot;i++) L[i]=R[i-1]+1,R[i]=i*block; R[tot]=n;
for(int i=1;i<=tot;i++){ int maxx=0; for(int j=i;j<=tot;j++){ for(int k=L[j];k<=R[j];k++) maxx=max(maxx,++cnt[a[k]]); for(int k=L[j];k<=R[j];k++) maxx=max(maxx,++cnt[a[k]]); ans[i][j]=maxx; } memset(cnt,0,sizeof(cnt)); } int lst=0;
int lst=0; while(q--){ int l=read()^lst,r=read()^lst; int maxx=0; if(belong[r]-belong[l]<=2){2 行未改动 lst=maxx,write(maxx),putchar('\n'); continue; } maxx=ans[belong[l]+1][belong[r]-1]; for(int i=l;i<=R[belong[l]];i++) for(int i=l;i<=R[belong[l]];i++) for(int j=pre[i]+maxx;j<v[a[i]].size()&&v[a[i]][j]<=r;++j) ++maxx; for(int i=L[belong[r]];i<=r;i++) for(int i=L[belong[r]];i<=r;i++) for(int j=pre[i]-maxx;j>=0&&v[a[i]][j]>=l;--j) ++maxx; lst=maxx,write(maxx),putchar('\n'); } fwrite(buffer,1,op1+1,stdout),op1=-1;20 行未改动