原题传送门

神鱼说这道题是强制离线(smog

\(mul*x+plus\)

\(mul=1,plus=0\)

\(val_{new}\)

\(val\),将总和更新

\(0\),见操作4

\(val\),将总和更新

操作5/6:val[pos[x]]或总和

有除法,要处理逆元

#include <bits/stdc++.h>
#define N 100005
#define mod 10000019
#define getchar nc
using namespace std;
inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
    register int x=0,f=1;register char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return x*f;
}
inline void write(register int x)
{
    if(!x)putchar('0');if(x<0)x=-x,putchar('-');
    static int sta[20];register int tot=0;
    while(x)sta[tot++]=x%10,x/=10;
    while(tot)putchar(sta[--tot]+48);
}
inline int fastpow(register int a,register int b)
{
	int res=1;
	while(b)
	{
		if(b&1)
			res=1ll*res*a%mod;
		a=1ll*a*a%mod;
		b>>=1;
	}
	return res;
}
int n,m,t,ans,b[N*100],tot,sum,mul=1,pls,inv=1,f[N],in[N];
inline void modify(register int x,register int y)
{
	sum=(sum+1ll*(mod-f[x])*mul+mod-pls)%mod;
	f[x]=1ll*(y-pls+mod)*inv%mod;
	if(!in[x])
		b[++tot]=x,in[x]=1;
	sum=(sum+y)%mod;
}
inline void plu(register int y)
{
	sum=(sum+1ll*n*y)%mod;
	pls=(pls+y)%mod;
}
inline void cover(register int y)
{
	while(tot)
		f[b[tot]]=0,in[b[tot--]]=0;
	mul=inv=1,pls=y;
	sum=1ll*n*y%mod;
}
inline void mult(register int y,register int z)
{
	if(y)
	{
		sum=1ll*sum*y%mod;
		mul=1ll*mul*y%mod;
		pls=1ll*pls*y%mod;
		inv=1ll*inv*z%mod;
	}
	else
		cover(0);
}
inline int query(register int x)
{
	return (1ll*f[x]*mul+pls)%mod;
}
int opt[N],x[N],y[N],z[N];
int main()
{
	n=read()%mod,m=read();
	for(register int i=0;i<m;++i)
	{
		opt[i]=read();
		if(opt[i]==1||opt[i]==5)
			x[i]=b[++tot]=read();
		if(opt[i]<=4)
			y[i]=(read()%mod+mod)%mod,z[i]=fastpow(y[i],mod-2);
	}
	sort(b+1,b+1+tot);
	tot=unique(b+1,b+1+tot)-b-1;
	for(register int i=0;i<m;++i)
		if(opt[i]==1||opt[i]==5)
			x[i]=lower_bound(b+1,b+1+tot,x[i])-b;
	t=read();
	for(register int i=tot=0;i<t;++i)
	{
		int a=read()%m,b=read()%m;
		for(register int j=0,k=(a+b)%m;j<m;++j,k=(k+b)%m)
		{
			int o=opt[k];
			if(o==1)
				modify(x[k],y[k]);
			else if(o==2)
				plu(y[k]);
			else if(o==3)
				mult(y[k],z[k]);
			else if(o==4)
				cover(y[k]);
			else if(o==5)
				ans=(ans+query(x[k]))%mod;
			else 
				ans=(ans+sum)%mod;
		}
	}
	write(ans);
	return 0;
}

相关文章:

  • 2022-01-23
  • 2022-02-13
  • 2021-05-28
  • 2022-12-23
  • 2021-10-02
  • 2021-11-21
  • 2021-07-06
  • 2021-09-10
猜你喜欢
  • 2021-08-08
  • 2021-10-19
  • 2021-06-07
  • 2022-02-21
  • 2021-11-24
  • 2022-12-23
  • 2022-02-28
相关资源
相似解决方案