传送门

设置一个 v i s [ i ] vis[i] vis[i]表示大小为 i i i的有几个数

那么每次查找若小区间内的数都相等就可以一起修改了

然后就是要记得 p u s h _ d o w n push\_down push_down其余没什么

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mid (l+r>>1)
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lson ls,l,mid
#define rson rs,mid+1,r
const int maxn = 4e5+10;
const int inf = -1e9;
int mi[maxn],mx[maxn],laz[maxn],vis[maxn];
void push_up(int rt,int l,int r)
{
	mi[rt] = min( mi[ls],mi[rs] );
	mx[rt] = max( mx[ls],mx[rs] );
}
void push_down(int rt,int l,int r)
{
	if( laz[rt]==-inf )	return;
	if( l!=r )
		laz[ls]=mi[ls]=mx[ls]=laz[rs]=mi[rs]=mx[rs]=laz[rt];
	laz[rt] =-inf;
}
void update(int rt,int l,int r,int L,int R,int val)
{
	if( l>R||r<L )	return;
	push_down(rt,l,r);
	if( l>=L&&r<=R&&mx[rt]==mi[rt] )
	{
		vis[mx[rt]]-=(r-l+1);
		vis[val]+=(r-l+1);
		laz[rt]=mx[rt]=mi[rt]=val;
		return;
	}
	update(lson,L,R,val); update(rson,L,R,val);
	push_up(rt,l,r);
}
signed main()
{
	int n,c,q;	scanf("%lld%lld%lld",&n,&c,&q);
	laz[1] = mx[1] = mi[1] = 1, vis[1] = n;
	while( q-- )
	{
		int x,y,a,b; scanf("%lld%lld%lld%lld",&x,&y,&a,&b);
		int p = vis[x];
		int l = (a+(p+b)%n*(p+b)%n )%n+1;
		int r = (a+p*b%n*p%n*b%n)%n+1;
		update( 1,1,n,min(l,r),max(l,r),y);
	}
	int ans = 0;
	for(int i=1;i<=c;i++)
		ans = max( ans,vis[i] );
	cout << ans;
}

还有完全暴力的

不设置 v i s vis vis数组,专门写函数来查找一定范围内 x x x的个数

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mid (l+r>>1)
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lson ls,l,mid
#define rson rs,mid+1,r
const int maxn = 4e5+10;
const int inf = -1e9;
map<int,int>mp;
int mi[maxn],mx[maxn],laz[maxn];
void push_up(int rt,int l,int r)
{
	mi[rt] = min( mi[ls],mi[rs] );
	mx[rt] = max( mx[ls],mx[rs] );
}
void push_down(int rt,int l,int r)
{
	if( laz[rt]==-inf )	return;
	if( l!=r )
		laz[ls]=mi[ls]=mx[ls]=laz[rs]=mi[rs]=mx[rs]=laz[rt];
	laz[rt] =-inf;
}
void build(int rt,int l,int r)
{
	laz[rt] = -inf;
	if( l==r ){ mi[rt]=mx[rt]=1; return; }
	build(lson); build(rson);
	push_up(rt,l,r);
}
void update(int rt,int l,int r,int L,int R,int val)
{
	if( l>R||r<L )	return;
	if( l>=L&&r<=R ){ laz[rt]=mx[rt]=mi[rt]=val; return; }
	push_down(rt,l,r);
	update(lson,L,R,val); update(rson,L,R,val);
	push_up(rt,l,r);
}
int ask(int rt,int l,int r,int L,int R,int val)
{
	if( l>R||r<L )	return 0;
	if( l>=L&&r<=R )//完全在区间内 
	{
		if( mx[rt]<val||mi[rt]>val )	return 0;
		if( mx[rt]==mi[rt]&&mx[rt]==val )	return r-l+1;
	}
	push_down(rt,l,r);
	return ask(lson,L,R,val)+ask(rson,L,R,val);
}
int get(int rt,int l,int r,int index)
{
	if( l>index||r<index )	return 0;
	if( l==r&&r==index )	return mi[rt];
	push_down(rt,l,r);
	return get(lson,index)+get(rson,index);
}
signed main()
{
	int n,c,q;	scanf("%lld%lld%lld",&n,&c,&q);
	build(1,1,n);
	while( q-- )
	{
		int x,y,a,b; scanf("%lld%lld%lld%lld",&x,&y,&a,&b);
		int p = ask(1,1,n,1,n,x);
		int l = (a+(p+b)*(p+b) )%n+1;
		int r = (a+p*b%n*p%n*b%n)%n+1;
		update( 1,1,n,min(l,r),max(l,r),y);
	}
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		int x = get(1,1,n,i);
		mp[x]++;
		ans = max( ans,mp[x] );
	}
	cout << ans;
}