#include<bits/stdc++.h>
#define int long long
using namespace std;
int d[1000001],q,m;

void upd(int pos,int c,int p,int s,int t){
	//cout << "\n" << p;
	if (s==t){
		d[p]=c;
		return;
	}
	int mid=(s+t)>>1;
	if (pos<=mid)upd(pos,c,p*2,s,mid);
	if (pos>mid)upd(pos,c,p*2+1,mid+1,t);
	d[p]=d[p*2]*d[p*2+1]%m;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        cin >> q >> m;
        fill(d,d+q*4+1,1);
		int tmp=q,ope,y,nnt=0;
        while(tmp--){
            cin >> ope >> y;
            if (ope==1){
                //cout << y << " ";
                upd(++nnt,y,1,1,q*4);
                cout << "\nd:";
                for (int i=1;i<=4*q;i++){
                    cout << d[i]<<" ";
                }
                cout <<"\n";
                cout << d[1]%m << "\n";
            }else{
                upd(y,1,1,1,q*4);
                cout << "\nd:";
                for (int i=1;i<=4*q;i++){
                    cout << d[i]<<" ";
                }
                cout <<"\n";
                cout << d[1]%m << "\n";
            }
        }
    }



    return 0;
} 


0 comments

No comments so far...

Information

ID
288
Time
1000ms
Memory
256MiB
Difficulty
7
Tags
# Submissions
55
Accepted
12
Uploaded By