提交时间:2022-05-06 22:36:03

运行 ID: 49412

#include <bits/stdc++.h> using namespace std; const int DVS = 1e9 + 7; const int MXN = 200005; int cnt[MXN], N, M, T, ans = 1; typedef long long ll; int read() { int x(0); char c(getchar()); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); return x; } void write(int x) { if (x >= 10) write(x / 10); putchar((x % 10) | 48); } void exgcd(int a, int b, ll& x, ll& y) { if (!b) x = 1, y = 0; else exgcd(b, a % b, y, x), y -= a / b * 1LL * x; } int inv(int x) { ll y(0), z(0); exgcd(x, DVS, y, z); return (y % DVS + DVS) % DVS; } int main() { N = read(), M = read(), T = read(); for (int y(0); M--;) { read(), y = read() - 1; ++cnt[y]; } for (int i(1); i != N; ++i) ans = ans * 1LL * cnt[i] % DVS; write(ans), putchar(10); for (int y(0); T--;) { read(), y = read() - 1; ans = ans * 1LL * inv(cnt[y]) % DVS * 1LL * (cnt[y] + 1) % DVS; ++cnt[y]; write(ans), putchar(10); } return 0; }