标签:模拟 ref 答案 mes har ble getchar new putc
#include <bits/stdc++.h>
#define N 100005
#define ll long long
#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 ll read()
{
register ll 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);
}
int n;
ll mod;
struct SegmentTree{
ll mul[N<<3];
inline void init(register int x,register int l,register int r)
{
mul[x]=1;
if(l==r)
return;
int mid=l+r>>1;
init(x<<1,l,mid);
init(x<<1|1,mid+1,r);
}
inline void pushup(register int x)
{
mul[x]=mul[x<<1]*mul[x<<1|1]%mod;
}
inline void update(register int x,register int l,register int r,register int pos,register int v)
{
if(l==r)
{
mul[x]=v;
return;
}
int mid=l+r>>1;
if(pos<=mid)
update(x<<1,l,mid,pos,v);
else
update(x<<1|1,mid+1,r,pos,v);
pushup(x);
}
}tr;
int main()
{
int T=read();
while(T--)
{
n=read(),mod=read();
tr.init(1,1,n);
for(register int i=1;i<=n;++i)
{
int opt=read();
ll x=read();
if(opt==1)
tr.update(1,1,n,i,x);
else
tr.update(1,1,n,x,1);
write(tr.mul[1]),puts("");
}
}
return 0;
}
【题解】Luogu P4588 [TJOI2018]数学计算
标签:模拟 ref 答案 mes har ble getchar new putc
原文地址:https://www.cnblogs.com/yzhang-rp-inf/p/10335121.html