踩坑总结 10pts 22pts
查看原帖
踩坑总结 10pts 22pts
1372132
cshur楼主2025/6/22 20:50

1. 10pts

for(int i = 1; i <= n; i++)
		if(Id[i] != Id[i-1])
			group[cnt-1].second = i-1,
			group[cnt].first = i;
      //cnt 应是 ++cnt 

2. 22pts

首先

for(int i = group[Id[last_L]].first; i <= group[Id[last_L]].second; i++)
        st[i] = ed[i] = 0;

应是

for(int i = /*group[Id[last_L]].first*/l; i <= /*group[Id[last_L]].second*/r; i++)
					st[a[i]] = ed[a[i]] = 0;

group[Id[last_L]].first 即块的左端点,右端点同理

其次

if(Id[L] == Id[R])
{//这里应初始化 st 数组
  for(int i = L; i <= R; i++)
  {
    if(st[a[i]] == 0)
      st[a[i]] = i;
    Ans[id] = max(Ans[id],i-st[a[i]]);
  }
  for(int i = L; i <= R; i++)
    st[a[i]] = 0;
}

应是

if(Id[L] == Id[R])
{
  for(int i = L; i <= R; i++)
    st[a[i]] = 0;//
  for(int i = L; i <= R; i++)
  {
    if(st[a[i]] == 0)
      st[a[i]] = i;
    Ans[id] = max(Ans[id],i-st[a[i]]);
  }
  for(int i = L; i <= R; i++)
    st[a[i]] = 0;
}

3.其他

认真核对这几处:

bool mo(query x,query y)
{
	if(Id[x.l] == Id[y.l])
		return x.r < y.r;//这里,不能奇偶优化
	return Id[x.l] < Id[y.l];
}
void add0(int x)
{
	if(!ed0[a[x]]) ed0[a[x]] = x;
	ans0 = max(ans0,max(ed[a[x]],ed0[a[x]])-x);
  //这行 max(ed[a[x]],ed0[a[x]]) 而不是 ed0[a[x]],原因见第一篇题解
}

祝大家 AC 愉快

2025/6/22 20:50
加载中...