原题:https://www.luogu.org/problemnew/show/P4588
题解:很明显是线段树,单点修改,区间查询。别忘了清1
#include<bits/stdc++.h>
#define ll long long
#define ls now<<1
#define rs now<<1|1
#define lson ls,l,mid
#define rson rs,mid+1,r
#define mid (l+r)/2
using namespace std;
const int N=1e5+10;
int cas,n,M,cnt;
ll tt[N<<2];
inline int rd(){
int x=0;int f=1;char s=getchar();
while(!isdigit(s)) f=(s=='-'?-1:f),s=getchar();
while(isdigit(s)) x=(x<<1)+(x<<3)+s-'0',s=getchar();
return x*f;
}
inline void upd(int now){
tt[now]=tt[ls]*tt[rs]%M;
}
void build(int now,int l,int r){
if(l==r){
tt[now]=1;return ;
}
build(lson);
build(rson);
upd(now);
}
void change(int now,int l,int r,int x,int c){
if(l==x && r==x){
tt[now]=c;
return ;
}
if(x<=mid) change(lson,x,c);
if(mid<x) change(rson,x,c);
upd(now);
}
ll query(int now,int l,int r,int x,int y){
if(x<=l && r<=y){
return tt[now];
}
ll ans=1;
if(x<=mid) ans=ans*query(lson,x,y)%M;
if(mid<y) ans=ans*query(rson,x,y)%M;
return ans;
}
int main(){
// freopen("math.in","r",stdin);
cas=rd();
while(cas--){
n=rd();M=rd();
build(1,1,n+1);
for(int i=1;i<=n;i++){
int opt=rd();int y=rd();
if(opt==1){
change(1,1,n+1,i,y);
printf("%lld\n",query(1,1,n+1,1,i));
}else {
change(1,1,n+1,y,1);
printf("%lld\n",query(1,1,n+1,1,i));
}
}
}
return 0;
}