社区讨论
求助 __int128了还是输出负数
P2023[AHOI2009] 维护序列参与者 4已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @lo9kyf22
- 此快照首次捕获于
- 2023/10/28 13:06 2 年前
- 此快照最后确认于
- 2023/10/28 13:06 2 年前
WA on #9 line 23959
源代码:
CPP#include<bits/stdc++.h>
using namespace std;
inline int re()
{
int x=0;char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9'){x=x*10+(ch&15);ch=getchar();}
return x;
}
#define int __int128
struct xxxx
{
int l,r,s,add=0,pls=1;
};
const int N=100001;int M;
class xxx
{
public:
int a[N],n;xxxx t[4*N];
inline void xfa(int p)
{
int c1=p<<1,c2=p<<1|1;
t[c1].add+=t[p].add;t[c2].add+=t[p].add;
t[c1].add%=M;t[c2].add%=M;
t[c1].s+=t[p].add*(t[c1].r-t[c1].l+1)%M;
t[c2].s+=t[p].add*(t[c2].r-t[c2].l+1)%M;
t[c1].s%=M;t[c2].s%=M;
t[p].add=0;
}
inline void xfp(int p)
{
int c1=p<<1,c2=p<<1|1;
t[c1].pls*=t[p].pls;t[c2].pls*=t[p].pls;
t[c1].pls%=M;t[c2].pls%=M;
t[c1].add*=t[p].pls;t[c2].add*=t[p].pls;
t[c1].add%=M;t[c2].add%=M;
t[c1].s*=t[p].pls;t[c2].s*=t[p].pls;
t[c1].s%=M;t[c2].s%=M;
t[p].pls=1;
}
int build(int l,int r,int p)//st l=1,r=n,p=1
{
t[p].l=l;t[p].r=r;
if(l==r)
{
a[l]%=M;
t[p].s=a[l];
return a[l];
}
int m=(l+r)>>1;
int c1=p<<1,c2=p<<1|1;
t[p].s=build(l,m,c1)+build(m+1,r,c2);
t[p].s%=M;
return t[p].s;
}
int jia(int l,int r,int x,int p)//st p=1
{
if(t[p].l>r||t[p].r<l)return 0;
if(t[p].l>=l&&t[p].r<=r)
{
int ad=(__int128)(t[p].r-t[p].l+1)*x%M;
t[p].s+=ad;t[p].s%=M;
t[p].add+=x;t[p].add%=M;
return ad;
}
xfp(p);xfa(p);
int c1=p<<1,c2=p<<1|1;
int ad=jia(l,r,x,c1)+jia(l,r,x,c2);ad%=M;
t[p].s+=ad;t[p].s%=M;
return ad;
}
int cheng(int l,int r,int x,int p)//st p=1
{
if(t[p].l>r||t[p].r<l)return 0;
if(t[p].l>=l&&t[p].r<=r)
{
int ad=t[p].s*(x-1)%M;
t[p].s+=ad;t[p].s%=M;
t[p].add*=x;t[p].add%=M;
t[p].pls*=x;t[p].pls%=M;
return ad;
}
xfp(p);xfa(p);
int c1=p<<1,c2=p<<1|1;
int ad=cheng(l,r,x,c1)+cheng(l,r,x,c2);ad%=M;
t[p].s+=ad;t[p].s%=M;
return ad;
}
int he(int l,int r,int p)//st p=1
{
if(t[p].l>r||t[p].r<l)return 0;
if(t[p].l>=l&&t[p].r<=r)return t[p].s;
xfp(p);xfa(p);
int c1=p<<1,c2=p<<1|1;
return (he(l,r,c1)+he(l,r,c2))%M;
}
}xds;
signed main()
{
ios::sync_with_stdio(false);
int n=re(),m;M=re();xds.n=n;
for(int i=1;i<=n;i++)
xds.a[i]=re();m=re();
xds.build(1,n,1);
for(int i=1;i<=m;i++)
{
int c1;c1=re();
if(c1==1)
{
int c2=re(),c3=re(),c4=re();
xds.cheng(c2,c3,c4,1);
}
if(c1==2)
{
int c2=re(),c3=re(),c4=re();
xds.jia(c2,c3,c4,1);
}
if(c1==3)
{
int c2=re(),c3=re();
printf("%d\n",xds.he(c2,c3,1));
}
}
return 0;
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...