1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| #include<iostream> #include<cstdio> #include<stack> #include<queue> #include<deque> #include<vector> #include<cstdlib> #include<string> #include<cstring> #include<algorithm> #include<ctime> #include<bitset> #include<set> #include<cmath> using namespace std;
#define rint register int #define Int64 long long #define max(x,y) (((x)>(y))?(x):(y)) #define min(x,y) (((x)<(y))?(x):(y)) #define clr(x,y) memset(x,y,sizeof(x)) #define sqar(x) (x)*(x) #define lowbit(x) (x&(-x)) #define swp(x,y) x^=y,y^=x,x^=y #define Maxn 100005
class Segment_tree{ private: Int64 databank[Maxn<<2]; Int64 Mod;
public: void SetMod(int M){Mod=M;}
void pushup(int nowpos){ databank[nowpos]=(databank[nowpos<<1]*databank[nowpos<<1|1])%Mod; }
void init(int nowpos,int L,int R){ if(L==R){databank[nowpos]=1;return;} int mid=L+R>>1; init(nowpos<<1,L,mid); init(nowpos<<1|1,mid+1,R); pushup(nowpos); }
void modify(int nowpos,int L,int R,int pur,int val){ if(L==R&&L==pur){ databank[nowpos]=val; return; } int mid=L+R>>1; if(pur<=mid)modify(nowpos<<1,L,mid,pur,val); if(pur>mid)modify(nowpos<<1|1,mid+1,R,pur,val); pushup(nowpos); }
void output(){cout<<databank[1]<<endl;} }S;
inline void read(int &x){ x=0;char c=getchar();while(c<'0'||c>'9'){c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-48;c=getchar();} }
int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t;read(t); while(t--){ int q,m;read(q);read(m); S.SetMod(m); S.init(1,1,q); for(int i=1;i<=q;i++){ int op,v;read(op);read(v); if(op==1)S.modify(1,1,q,i,v),S.output(); else{ S.modify(1,1,q,v,1); S.output(); } } } return 0; }
|