You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
683 B
C++
31 lines
683 B
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
typedef long long ll;
|
|
const int N = 1e5 + 50;
|
|
ll f[N];
|
|
int main()
|
|
{
|
|
int T;
|
|
scanf("%d", &T);
|
|
for (int t = 1; t <= T; t++)
|
|
{
|
|
printf("Case #%d:\n", t);
|
|
int q, m, op, x;
|
|
scanf("%d%d", &q, &m);
|
|
ll ans = 1;
|
|
for (int i = 1; i <= q; i++)
|
|
{
|
|
scanf("%d%d", &op, &x);
|
|
if (op == 1)
|
|
ans = ans * (f[i] = x) % m;
|
|
else
|
|
{
|
|
ans = f[x] = f[i] = 1;
|
|
for (int j = 1; j < i; j++)
|
|
ans = ans * f[j] % m;
|
|
}
|
|
printf("%lld\n", ans);
|
|
}
|
|
}
|
|
return 0;
|
|
} |