牛客编程巅峰赛S2第11场 - 钻石&王者T3大逃离题解
简单数学
#牛客编程巅峰赛##题解#
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 * @param k int整型 * @param Point int整型vector * @return int整型vector */ typedef long long ll; ll mod = 1e9 + 7; pair<int, int> a[200010]; vector<int> v; ll inv[200010], fact[200010]; ll ans[200010]; inline ll power(ll a, ll b) { ll res = 1; for (; b; b >>= 1ll) { if (b & 1ll) res = res * a % mod; a = a * a % mod; } return res; } inline ll C(ll a, ll b) { if (b == 0) return 1; return fact[a] * inv[b] % mod * inv[a - b] % mod; } vector<int> city(int n, int k, vector<int>& Point) { for (int i = 0; i < n; i++) a[i + 1] = { Point[i], i + 1 }; sort(a + 1, a + n + 1); fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod; inv[0] = 1; for (int i = 1; i <= n; i++) inv[i] = inv[i - 1] * power(i, mod - 2) % mod; for (int i = 1; i <= n; i++) { if (i < k) ans[a[i].second] = 0; else ans[a[i].second] = C(i - 1, k - 1) * fact[k] % mod * fact[n - k] % mod * inv[n] % mod; } for (int i = 1; i <= n; i++) v.push_back(ans[i]); return v; } };
#牛客编程巅峰赛##题解#