首页 > 其他分享 >「杂题乱刷」洛谷 P2572

「杂题乱刷」洛谷 P2572

时间:2024-03-13 12:44:39浏览次数:29  
标签:洛谷 forl bl Sum len id sum 杂题 P2572

先上 AC 代码:

点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
*/
#include<bits/stdc++.h>
using namespace std;
#define map unordered_map
#define forl(i,a,b) for(register long long i=a;i<=b;i++)
#define forr(i,a,b) for(register long long i=a;i>=b;i--)
#define forll(i,a,b,c) for(register long long i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(register long long i=a;i>=b;i-=c)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid ((l+r)>>1)
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) x&-x
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define ll long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
ll t,sq;
struct node{
	ll L,R,sum,fir,firpd,beh,behpd,tag,fugai,len,max1,max0,max1pd,max0pd; 
}bl[100010];
ll a[100010],b[100010],n,m;
void upd(ll id)
{
	if(bl[id].fugai!=-1)
	{
		forl(i,bl[id].L,bl[id].R)
			a[i]=bl[id].fugai;
		bl[id].fir=bl[id].len;
		bl[id].beh=bl[id].len;
		bl[id].firpd=bl[id].fugai;
		bl[id].behpd=bl[id].fugai;
		bl[id].sum=bl[id].fugai*bl[id].len;
		
		bl[id].max1=bl[id].fugai*bl[id].len;
		bl[id].max0=(bl[id].fugai^1)*bl[id].len;
		bl[id].max1pd=1;
		bl[id].max0pd=1;		
		
		bl[id].fugai=-1;
		bl[id].tag=0;
		return ;
	}
	if(bl[id].tag)
		forl(i,bl[id].L,bl[id].R)
			a[i]^=1;
	bl[id].sum=0,bl[id].fir=0,bl[id].firpd=0,bl[id].beh=0,bl[id].behpd=0,bl[id].fugai=-1,bl[id].tag=0;
	
	ll sum=0,Maxn=0;
	forl(j,bl[id].L,bl[id].R)
	{
		if(a[j]==1)
			sum++;
		else
			Maxn=max(Maxn,sum),sum=0;
	}
	bl[id].max1=max(Maxn,sum);
	sum=0,Maxn=0;
	forl(j,bl[id].L,bl[id].R)
	{
		if(a[j]==0)
			sum++;
		else
			Maxn=max(Maxn,sum),sum=0;
	}
	bl[id].max0=max(Maxn,sum);bl[id].max0pd=1;bl[id].max1pd=1;

	ll Sum=0;
	forl(j,bl[id].L,bl[id].R)
		Sum+=a[j];
	forl(j,bl[id].L+1,bl[id].R)
	{
		if(a[bl[id].L]==a[j])
			bl[id].fir++;
		else
			break;
	}
	bl[id].fir++;
	forr(j,bl[id].R-1,bl[id].L)
	{
		if(a[bl[id].R]==a[j])
			bl[id].beh++;
		else
			break;
	}
	bl[id].beh++;
	bl[id].sum=Sum;
	if(a[bl[id].L])
		bl[id].firpd=1;
	if(a[bl[id].R])
		bl[id].behpd=1;		

}
void upd1(ll l,ll r)
{
	if(b[l]==b[r])
	{
		upd(b[l]);
		forl(i,l,r)
			a[i]=0;
		upd(b[l]);
		return ;
	}
	upd(b[l]);
	forl(i,l,bl[b[l]].R)
		a[i]=0;
	upd(b[l]);
	upd(b[r]);
	forl(i,bl[b[r]].L,r)
		a[i]=0;
	upd(b[r]);
	forl(i,b[l]+1,b[r]-1)
		bl[i].fugai=0,bl[i].sum=0,bl[i].fir=bl[i].len,bl[i].beh=bl[i].len,
		bl[i].firpd=0,bl[i].behpd=0,bl[i].tag=0,
		
		bl[i].max1=bl[i].fugai*bl[i].len,
		bl[i].max0=(bl[i].fugai^1)*bl[i].len,
		bl[i].max1pd=1,
		bl[i].max0pd=1;
}
void upd2(ll l,ll r)
{
	if(b[l]==b[r])
	{
		upd(b[l]);
		forl(i,l,r)
			a[i]=1;
		upd(b[l]);
		return ;
	}
	upd(b[l]);
	forl(i,l,bl[b[l]].R)
		a[i]=1;
	upd(b[l]);
	upd(b[r]);
	forl(i,bl[b[r]].L,r)
		a[i]=1;
	upd(b[r]);
	forl(i,b[l]+1,b[r]-1)
		bl[i].fugai=1,bl[i].sum=bl[i].len,bl[i].fir=bl[i].len,bl[i].beh=bl[i].len,
		bl[i].firpd=1,bl[i].behpd=1,bl[i].tag=0,		
		
		bl[i].max1=bl[i].fugai*bl[i].len,
		bl[i].max0=(bl[i].fugai^1)*bl[i].len,
		bl[i].max1pd=1,
		bl[i].max0pd=1;
}
void upd3(ll l,ll r)
{
	if(b[l]==b[r])
	{
		upd(b[l]);
		forl(i,l,r)
			a[i]^=1;
		upd(b[l]);
		return ;
	}
	upd(b[l]);
	forl(i,l,bl[b[l]].R)
		a[i]^=1;
	upd(b[l]);
	upd(b[r]);
	forl(i,bl[b[r]].L,r)
		a[i]^=1;
	upd(b[r]);
	forl(i,b[l]+1,b[r]-1)
	{
		if(bl[i].fugai==-1)
			bl[i].sum=bl[i].len-bl[i].sum,bl[i].firpd^=1,bl[i].behpd^=1,bl[i].tag^=1,swap(bl[i].max1,bl[i].max0);
		else
		{
			bl[i].fugai^=1;
			if(bl[i].fugai==1)
				bl[i].sum=bl[i].len,bl[i].fir=bl[i].len,bl[i].beh=bl[i].len,bl[i].firpd=1,bl[i].behpd=1;
			else
				bl[i].sum=0,bl[i].fir=bl[i].len,bl[i].beh=bl[i].len,bl[i].firpd=0,bl[i].behpd=0;
			
			bl[i].max1=bl[i].fugai*bl[i].len;
			bl[i].max0=(bl[i].fugai^1)*bl[i].len;
			bl[i].max1pd=1;
			bl[i].max0pd=1;
		}
	}
}
ll query1(ll l,ll r)
{
	if(b[l]==b[r])
	{
		ll Sum=0;
		upd(b[l]);
		forl(i,l,r)
			Sum+=a[i];
		return Sum;
	}
	ll Sum=0;
	upd(b[l]);
	forl(i,l,bl[b[l]].R)
		Sum+=a[i];
	upd(b[r]);
	forl(i,bl[b[r]].L,r)
		Sum+=a[i];
	forl(i,b[l]+1,b[r]-1)
		Sum+=bl[i].sum;
	return Sum;
}
ll query2(ll l,ll r)
{
	ll Sum=0,maxn=0;
	if(b[l]==b[r])
	{
		upd(b[l]);
		forl(i,l,r)
		{
			if(a[i])
				Sum++;
			else
				maxn=max(maxn,Sum),Sum=0;
		}
		return max(maxn,Sum);
	}
	upd(b[l]);
	upd(b[r]);
	forl(i,l,bl[b[l]].R)
	{
		if(a[i])
			Sum++;
		else
			maxn=max(maxn,Sum),Sum=0;
	}
	forl(i,b[l]+1,b[r]-1)
	{
		if(bl[i].fir*bl[i].firpd==bl[i].len)
		{
			Sum+=bl[i].len;
			continue;
		}
	/*	else if(bl[i].fir==bl[i].len)
		{
			maxn=max(maxn,Sum);
			Sum=0;
			continue;
		}*/
		else
		{
			Sum+=bl[i].fir*bl[i].firpd;
			maxn=max(maxn,Sum);
			Sum=bl[i].beh*bl[i].behpd;
		}
	//	if(bl[i].firpd+bl[i].behpd==0)
		maxn=max(maxn,bl[i].max1);
	}
	forl(i,bl[b[r]].L,r)
	{
		if(a[i]==1)
			Sum++;
		else
			maxn=max(maxn,Sum),Sum=0;
	}
	return max(maxn,Sum);
}
void solve()
{
	cin>>n>>m;
	sq=pow(sqrt(n),0.66);
	forl(i,1,n)
		cin>>a[i];
	forl(i,1,n)
	{
		bl[i].L=bl[i-1].R+1;
		bl[i].R=min(n,i*sq);
		ll Sum=0;
		forl(j,bl[i].L,bl[i].R)
			Sum+=a[j],b[j]=i;
		forl(j,bl[i].L+1,bl[i].R)
		{
			if(a[bl[i].L]==a[j])
				bl[i].fir++;
			else
				break;
		}
		bl[i].fir++;
		forr(j,bl[i].R-1,bl[i].L)
		{
			if(a[bl[i].R]==a[j])
				bl[i].beh++;
			else
				break;
		}
		
		ll sum=0,Maxn=0;
		forl(j,bl[i].L,bl[i].R)
		{
			if(a[j]==1)
				sum++;
			else
				Maxn=max(Maxn,sum),sum=0;
		}
		bl[i].max1=max(Maxn,sum);
		sum=0,Maxn=0;
		forl(j,bl[i].L,bl[i].R)
		{
			if(a[j]==0)
				sum++;
			else
				Maxn=max(Maxn,sum),sum=0;
		}
		bl[i].max0=max(Maxn,sum);bl[i].max0pd=1;bl[i].max1pd=1;
		
		bl[i].beh++;
		bl[i].sum=Sum;
		bl[i].fugai=-1;
		bl[i].len=bl[i].R-bl[i].L+1;
		if(a[bl[i].L])
			bl[i].firpd=1;
		if(a[bl[i].R])
			bl[i].behpd=1;		
		if(bl[i].R==n)
			break;
	}
	while(m--)
	{
		ll opt,l,r;
		cin>>opt>>l>>r;
		l++,r++;
		if(opt==0)
			upd1(l,r);
		else if(opt==1)
			upd2(l,r);
		else if(opt==2)
			upd3(l,r);
		else if(opt==3)
			cout<<query1(l,r)<<endl;
		else
			cout<<query2(l,r)<<endl;
	/*	forl(i,1,n)
			upd(i);
		forl(i,1,n)
		{
			cout<<a[i]<<' ';
			if(i==706)
				cout<<endl;
		}
		cout<<endl;*/
	}
}
/*
1000 2
1 1 0 1 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 0 1 1 1 1 0 1 0 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 1 1 0 1 0 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 0 0 0 0 1 1 0 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 1 1 1 0 0 0 1 0 0 0 1 1 1 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 0 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 0 0 0 0 1 1 0 1 0 1 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1 1 0 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 0 1 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 1 0 1 1 1 0 0 0 1 1 0 1 0 1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 1 0 0 1 0 0 1 1 1 1 0 1 1 0 0 0 1 0 1 1 1 1 0 0 0 1 1 1 0 0 1 1 1 1 0 0 1 1 0 1 1 0 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1 1 1 1 0 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 0 0 1 1 0 0 1 1 0 1 1 1 1 1 1 0 0 1 0 0 1 0 0 1 0 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0 1 1 1 0 1 1 0 1 1 1 0 0 0 1 1 0 0 0 1 0 0 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 
2 894 952
1 902 924
2 496 718
4 159 328
3 430 951
4 706 758
6
282
5
*/
int main()
{
//	IOS;
	t=1;
//	cin>>t;
	while(t--)
		solve();
    /******************/
	/*while(L<q[i].l) */
	/*    del(a[L++]);*/
	/*while(L>q[i].l) */
	/*    add(a[--L]);*/
	/*while(R<q[i].r) */
	/*	  add(a[++R]);*/
	/*while(R>q[i].r) */
	/*    del(a[R--]);*/
    /******************/
	QwQ;
}
/*

*/
/*
100 16
0 0 1 1 1 1 1 1 1 1 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 1 1 0 1 0 1 1 1 0 0 1 0 1 
1 48 66
0 62 92
0 25 29
2 64 81
2 3 36
3 6 33
1 9 38
0 63 85
2 22 48
2 38 71
4 94 94
4 56 84
0 44 93
0 38 61
1 27 43
4 51 96
15
1
10
1
*/
/*
100 4
0 0 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 1 0 0 1 0 0 0 1 1 1 1 1 0 1 0 1 0 0 0 0 1 1 1 1 1 0 1 1 0 
2 36 46
4 76 89
1 76 97
4 42 67
5
6
*/
/*
10 10
1 0 1 0 1 1 0 0 1 1 
2 7 7
2 2 9
4 8 9
0 7 7
1 8 8
1 1 9
2 3 9
0 8 8
4 3 4
1 8 8
0
0
*/
/*
10 10
1 0 1 1 1 0 0 0 0 0 
3 4 5
1 2 5
4 4 4
0 8 9
0 7 8
1 6 7
4 5 9
1 2 6
4 0 5
3 9 9
1
1
3
4
0
*/
/*
10 10
0 0 1 1 1 1 1 0 0 0 
0 1 3
3 1 9
2 4 9
1 3 7
0 1 4
1 3 7
1 0 0
2 3 4
2 4 7
4 2 9

3
2
*/
/*
20 20
0 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 0 0 0 
4 5 8
4 1 8
4 7 7
4 0 8
3 3 6
4 0 8
1 0 9
3 0 2
2 6 9
0 3 7
1 0 8
0 2 4
2 9 9
3 3 3
0 0 7
1 1 6
1 1 4
1 0 6
3 4 8
3 1 7

4
4
1
4
3
4
3
0
4
6
*/

最需要注意的就是操作 \(4\) 了,这里我来提供几组 hack 数据:

若您使用分块做法,将块长调为 pow(sqrt(n),0.66) 后食用以下几组数据效果更佳。

1:

in:

1000 6
1 1 0 1 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 0 1 1 1 1 0 1 0 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 1 1 0 1 0 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 0 0 0 0 1 1 0 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 1 1 1 0 0 0 1 0 0 0 1 1 1 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 0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44 93
0 38 61
1 27 43
4 51 96

out:

15
1
10
1

3:

in:

100 4
0 0 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 1 0 0 1 0 0 0 1 1 1 1 1 0 1 0 1 0 0 0 0 1 1 1 1 1 0 1 1 0 
2 36 46
4 76 89
1 76 97
4 42 67

out:

5
6

4:

in:

10 10
1 0 1 0 1 1 0 0 1 1 
2 7 7
2 2 9
4 8 9
0 7 7
1 8 8
1 1 9
2 3 9
0 8 8
4 3 4
1 8 8

out:

0
0

5:

in:

10 10
1 0 1 1 1 0 0 0 0 0
3 4 5
1 2 5
4 4 4
0 8 9
0 7 8
1 6 7
4 5 9
1 2 6
4 0 5
3 9 9

out:

1
1
3
4
0

6:

in:

10 10
0 0 1 1 1 1 1 0 0 0 
0 1 3
3 1 9
2 4 9
1 3 7
0 1 4
1 3 7
1 0 0
2 3 4
2 4 7
4 2 9

out:

3
2

7:

in:

20 20
0 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 0 0 0 
4 5 8
4 1 8
4 7 7
4 0 8
3 3 6
4 0 8
1 0 9
3 0 2
2 6 9
0 3 7
1 0 8
0 2 4
2 9 9
3 3 3
0 0 7
1 1 6
1 1 4
1 0 6
3 4 8
3 1 7

out:

4
4
1
4
3
4
3
0
4
6

标签:洛谷,forl,bl,Sum,len,id,sum,杂题,P2572
From: https://www.cnblogs.com/wangmarui/p/18070364

相关文章

  • QOJ杂题合集
    QOJ杂题合集QOJ#151.NiceLinesQOJ#838.HorribleCyclesQOJ#894.LongestLooseSegmentQOJ#895.Color给定一个有\(n\)个节点的无向完全图\(G\),每条边都被染成了\(m\)种颜色中的一种,颜色编号为\(1\simm\)。我们称一个无向完全图合法,当且仅当对于\(\forallx......
  • 洛谷题单指南-线性表-P2234 [HNOI2002] 营业额统计
    原题链接:https://www.luogu.com.cn/problem/P2234题意解读:要计算每一天最小波动值的和,需要对每一天求最小波动值,再求和,如果暴力法,时间复杂度在1+2+3+......+32767≈5*10^8,可能会超时。解题思路:1、暴力法:由于本题测试数据比较水,实测暴力求解直接可以AC,由于没有技术含量,不做具体......
  • 「杂题乱刷」洛谷 P1708
    题目链接P1708解题思路解法一:考虑预处理,这部分可以直接打表。其他题解这部分讲的比较详细了,在此不再赘述。期望得分\(100\)分。解法二:考虑数位dp。这里采用记搜的写法。dfs(last,sum,maxsum,_1)分别表示还需要枚举几位数,目前枚举的数位和,可以枚举的最大数位和,是否均......
  • 洛谷题单指南-线性表-P4387 【深基15.习9】验证栈序列
    原题链接:https://www.luogu.com.cn/problem/P4387题意解读:判断一组序列入栈后,出栈序列的合法性。解题思路:数据长度100000,直接模拟堆栈的入栈和出栈即可遍历每一个入栈元素,依次入栈,每一个元素入栈后,比较栈顶元素和出栈序列第一个,如果相等,则出栈,持续进行比较、出栈直到不相等......
  • 洛谷题单指南-线性表-P1241 括号序列
    原题链接:https://www.luogu.com.cn/problem/P1241题意解读:括号配对问题,直观上是堆栈的应用。关键的匹配策略是读懂该句:考察它与它左侧离它最近的未匹配的的左括号。解题思路:本题所需核心数据结构是堆栈,由于要实现从栈顶找到第一个未匹配的左括号,所以堆栈中只存所有左括号。从......
  • 洛谷题单指南-线性表-P2058 [NOIP2016 普及组] 海港
    原题链接:https://www.luogu.com.cn/problem/P2058题意解读:计算24小时时间窗口内不同国家的数量,是队列的典型应用。解题思路:本题需要用到两个关键的数据结构:队列、数组队列用来保存24小时内到达的船的时间,数组用来保存24小时内每个国家有多少人每到一只船,需要把时间放入队列,如......
  • 洛谷题单指南-线性表-P1540 [NOIP2010 提高组] 机器翻译
    原题链接:https://www.luogu.com.cn/problem/P1540题意解读:本题模拟内存的调入调出,内存先入先出的特性就是队列。解题思路:本题需要两种数据结构:队列、数组队列用来模拟内存的操作,数组充当hash表用于判断单词在内存是否存在核心逻辑:对于每一个单词,如果内存不存在,查一次词典,再将......
  • 洛谷题单指南-线性表-P1160 队列安排
    原题链接:https://www.luogu.com.cn/problem/P1160题意解读:本题是双向链表的模拟题,要快速实现M个节点的删除,用数组模拟链表是最佳做法。解题思路:双向链表关键要实现好两个操作:voidadd(intk,intv);//在第k个节点后增加第v的号节点,即在k号同学右边插入v号同学voiddel(int......
  • 洛谷题单指南-线性表-P1996 约瑟夫问题
    原题链接:https://www.luogu.com.cn/problem/P1996题意解读:约瑟夫问题是队列的典型应用。解题思路:n个人围圈报数,可以直接基于数组实现循环队列操作,再定义额外数组记录每个人是否已经出圈即可。更直观的做法,定义队列,初始放入1~n,然后重复n次,每次从1~m报数,如果报数到m,直接出队,......
  • 洛谷题单指南-线性表-P3613 【深基15.例2】寄包柜
    原题链接:https://www.luogu.com.cn/problem/P3613题意解读:此题很容易想成用二维数组求解,但是最多有10^5*10^5个寄包柜格子,二维数据会爆空间,题目明确各自一共不超过10^7,所以需要动态数据结构vector。解题思路:vector的问题在于需要提前明确空间大小,才能进行随即访问操作,否则可......