0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-27 07:12:00 +00:00
OI-codes/Luogu/P4588/P4588.cpp

68 lines
1.2 KiB
C++
Raw Normal View History

2020-12-02 09:35:55 +00:00
#include <bits/stdc++.h>
using namespace std;
struct node {
int l, r;
long long s;
node() {
l = r = 0;
s = 0;
}
node(int _l, int _r) {
l = _l;
r = _r;
s = 0;
}
} tr[100005 << 2];
int t, q, mod, op, m;
void pushup(int u) {
tr[u].s = (tr[u << 1].s * tr[u << 1 | 1].s) % mod;
}
void build(int u, int l, int r) {
tr[u] = node(l, r);
if (l == r) {
tr[u].s = 1;
return;
}
int mid = l + r >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
pushup(u);
}
void modify(int u, int x, int v) {
if (tr[u].l == tr[u].r) {
tr[u].s = v;
return;
}
int mid = tr[u].l + tr[u].r >> 1;
if (x <= mid) {
modify(u << 1, x, v);
2021-11-19 09:01:13 +00:00
} else {
2020-12-02 09:35:55 +00:00
modify(u << 1 | 1, x, v);
}
pushup(u);
}
int main() {
cin >> t;
while (t--) {
cin >> q >> mod;
build(1, 1, q);
for (int i = 1; i <= q; i++) {
cin >> op >> m;
if (op == 1) {
modify(1, i, m);
2021-11-19 09:01:13 +00:00
} else if (op == 2) {
2020-12-02 09:35:55 +00:00
modify(1, m, 1);
}
cout << tr[1].s << endl;
}
}
return 0;
}