提交时间:2022-05-06 22:24:38

运行 ID: 49407

#include <bits/stdc++.h> using namespace std; const int DVS = 998244353; const int MXN = 200005; int cnt[MXN], N, M, T, ans = 1; void exgcd(int a, int b, int& x, int& y) { if (!b) x = 1, y = 0; else exgcd(b, a % b, y, x), y -= a / b * x; } int inv(int x) { int y(0), z(0); exgcd(x, DVS, y, z); return (y % DVS + DVS) % DVS; } int main() { scanf("%d%d%d", &N, &M, &T); for (int y(0); M--;) { scanf("%d", &y); scanf("%d", &y); --y; ++cnt[y]; } for (int i(1); i != N; ++i) ans = ans * 1LL * cnt[i] % DVS; printf("%d\n", ans); for (int y(0); T--;) { scanf("%d", &y); scanf("%d", &y); --y; ans = ans * 1LL * inv(cnt[y]) % DVS * (cnt[y] + 1) % DVS; ++cnt[y]; printf("%d\n", ans); } return 0; }