这题难道不是这样做的吗?
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5+10;
int t;
int q,mod;
int x,a[maxn],tot;
signed main(){
scanf("%lld",&t);
while(t--){
x=1,tot=1;
memset(a,0,sizeof a);
scanf("%lld%lld",&q,&mod);
while(q--){
int op;
scanf("%lld",&op);
if(op==1){
int m;
scanf("%lld",&m);
a[tot]=m;
x=(x*m)%mod;
printf("%lld\n",x);
}
if(op==2){
int pos;
scanf("%lld",&pos);
x=(x/a[pos])%mod;
printf("%lld\n",x);
}
tot++;
}
}
return 0;
}