跳到正文

题解

题解:AT_abc441_g [ABC441G] Takoyaki and Flip

anll约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年1月20日
收录
2026年1月20日
更新
2026年11月13日
篇幅
约 1 分钟

版本

  1. v1当前

分块做法,赛时没调出来。

对于每个位置,维护:

  • 当前位置章鱼烧的个数 ctct。
  • 当前位置被翻的次数 clcl。

对于每块,维护:

  • 整块加的 tag tttt。
  • 整块翻转的 tag tltl(也是翻转次数)。
  • 当前块正面的数量 nmnm。
  • 当前块的最大值 mxmx。

当散块操作或查询之前先重构(计算单点的 cl,ctcl,ct 和整块的 nmnm),操作或查询之后重算 mxmx。

重构时:

  • 对新的 clcl 是偶数(当前是上面)的位置,ctct 这么更新:
    • 如果 tl=0tl=0 要加上 tttt。
    • 如果 tl≠0tl\ne0 要赋值成 tttt。
  • 对新的 clcl 是奇数的位置要赋值成 00。
C++
void rbld(int x) {
	if(!tl[x]) {
		nm[x]=0;
		for(int i=L[x];i<=R[x];i++) {
			if(!(cl[i]&1)) ct[i]+=tt[x],nm[x]++;
			else ct[i]=0;
		}
		tt[x]=0;
		return;
	}
	nm[x]=0;
	for(int i=L[x];i<=R[x];i++) {
		cl[i]+=tl[x];
		if(!(cl[i]&1)) ct[i]=tt[x],nm[x]++;
		else ct[i]=0;
	}
	tt[x]=tl[x]=0;
}

整块操作直接打 tag 即可。

细节比较多,具体看代码。