0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-10 08:58:48 +00:00

P4588 [TJOI2018]数学计算

R43031870
This commit is contained in:
Baoshuo Ren 2020-12-02 17:35:55 +08:00 committed by Baoshuo Ren
parent 10439fda0d
commit cca58e92f2
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

69
problem/P4588/P4588.cpp Normal file
View File

@ -0,0 +1,69 @@
#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);
}
else {
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);
}
else if (op == 2) {
modify(1, m, 1);
}
cout << tr[1].s << endl;
}
}
return 0;
}