int a[100000]; intmain(){ int T; cin >> T; while (T--) { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); int k = (n + 1) / 2, ans = 0; for (int i = k; i <= n; i++) { if (a[i] == a[k]) ans++; } cout << ans << endl; } return0; }
#include<bits/stdc++.h> usingnamespace std; constlonglong mod = 1000000007ll;
longlong T, a[200010], SUM; voidwork(){ int n, k; SUM = 0; cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i], SUM += a[i], SUM %= mod; longlong ans = 0, sum = 0; for (int i = 1; i <= n; ++i) { sum += a[i]; if (sum > ans) { ans = sum; } elseif (sum < 0) { sum = 0; } } sum = 0; for (int i = 1; i <= k; ++i) { sum = (sum + ans) % mod; ans = (ans + ans) % mod; } cout << (SUM + sum + 2ll * mod) % mod << endl; }
intmain(){ cin >> T; while (T--) work(); return0; }
voidadd(int x, int y){ e[x].emplace_back(y); e[y].emplace_back(x); }
int cnt[100010], siz[100010]; // cnt: 可删边的个数 // siz: 不包含已经割掉的子树大小的大小 voiddfs(int fa, int u, int x){ cnt[u] = 0; siz[u] = 1; for (auto v: e[u]) { if (v == fa) continue; dfs(u, v, x); cnt[u] += cnt[v]; if (siz[v] >= x) { cnt[u]++; siz[v] = 0; } siz[u] += siz[v]; } }
boolcheck(int num){ dfs(-1, 1, num); if (siz[1] >= num) cnt[1]++; if (cnt[1] >= k + 1) returntrue; returnfalse; }
voidwork(){ cin >> n >> k; for (int i = 1; i <= n; i++) e[i].clear(); for (int i = 1, x, y; i < n; i++) { cin >> x >> y; add(x, y); } int l = 0, r = n, ans = 0; while (l <= r) { int mid = (l + r) >> 1; if (check(mid)) { l = mid + 1; ans = mid; } else r = mid - 1; } cout << ans << endl; }
intmain(){ int T; cin >> T; while (T--) work(); return0; }
constlonglong mod = 1000000007ll; longlong fac[200010], invFac[200010];
longlongqpow(longlong x, longlong p){ if (x == 0) return0; if (x == 1 || p == 0) return1; longlong ans = 1; while (p) { if (p & 1) ans = ans * x % mod; x = x * x % mod; p >>= 1ll; } return ans; }
voidinit(){ fac[0] = 1; for (int i = 1; i <= 200000; i++) fac[i] = (fac[i - 1] * i) % mod; invFac[200000] = qpow(fac[200000], mod - 2); for (int i = 199999; i >= 0; i--) invFac[i] = invFac[i + 1] * (i + 1) % mod; }
longlongC(int n, int m){ return (fac[n] * (invFac[n - m] * invFac[m] % mod) % mod); }
voidwork(){ int n, m1, m2; cin >> n >> m1 >> m2; vector<int> p(m1 + 1), s(m2 + 1); for (int i = 1, x; i <= m1; i++) cin >> p[i]; for (int i = 1, x; i <= m2; i++) cin >> s[i]; if (p[m1] != s[1] || p[1] != 1 || s[m2] != n) { cout << "0\n"; return ; } longlong ans1 = 1, ans2 = 1; for (int i = m1 - 1; i >= 1; i--) { ans1 = (ans1 * fac[p[i + 1] - 2] % mod) * invFac[p[i] - 1] % mod; } for (int i = 1; i < m2; i++) { ans2 = (ans2 * fac[n - s[i] - 1] % mod) * invFac[n - s[i + 1]] % mod; } cout << (ans1 * ans2 % mod) * C(n - 1, s[1] - 1) % mod << endl; }
intmain(){ init(); int T; cin >> T; while (T--) work(); return0; }