#include<bits/stdc++.h> using ll = longlong; usingnamespace std;
intmain(){ int t; cin >> t;
while (t--) { int n; cin >> n;
int x = (n + 1) / 2; if (x % 2 == 0) x--; int l = n - x >> 1, r = n - x - l; vector<int> res; for (int i = 0; i < x / 2; i++) { res.push_back(n); } for (int i = 0; i < l; i++) { res.push_back(i * 2 + 1); } res.push_back(n); for (int i = 0; i < r; i++) { res.push_back(i * 2 + 2); } for (int i = 0; i < x / 2; i++) { res.push_back(n); }
for (int i = 0; i < n; i++) { cout << res[i] << " "; } cout << endl; }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong;
intmain(){ int t; cin >> t;
while (t--) { int n; cin >> n;
vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; }
auto check = [&](int x, int y) { map<int, int> mp; // 前缀和出现的次数 mp[0] = 1; int now = 0; ll ans = 0; for (int i = 0; i < n; i++) { if (a[i] <= x) { now--; } elseif (a[i] >= y) { now++; } else { mp.clear(); // 中位数改变了 } ans += mp[now]; mp[now]++; } return ans; };
ll ans = 1LL * (n + 1) * n / 2; for (int x = 1; x <= 9; x++) { ans -= check(x, x + 1); } for (int x = 1; x < 9; x++) { ans += check(x, x + 2); } cout << ans << endl; }
#include<bits/stdc++.h> using ll = longlong; usingnamespace std;
constexprint mod = 998244353; constexprint N = 1e6 + 8; ll fac[N], ifac[N];
ll qpow(ll a, ll n){ ll res = 1; while (n) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll inv(ll n){ returnqpow(n, mod - 2); } ll C(int n, int m){ if (n < m || m < 0) return0; return fac[n] * ifac[m] % mod * ifac[n - m] % mod; } ll A(int n, int m){ return fac[n] * ifac[n - m] % mod; } ll Catalan(int n){ if (n <= 0) return1; return (C(n * 2, n) + mod - C(n * 2, n - 1)) % mod; }
intmain(){ int t; cin >> t;
fac[0] = ifac[0] = 1; for (int i = 1; i <= N - 1; i++) { fac[i] = fac[i - 1] * i % mod; } ifac[N - 1] = inv(fac[N - 1]); for (int i = N - 1; i > 0; i--) { ifac[i - 1] = ifac[i] * i % mod; }
while (t--) { int n, m; cin >> n >> m;
vector<array<int, 3>> seg(m); bool all = false; for (auto& [l, r, len] : seg) { cin >> l >> r; l--; len = r - l; if (len == n) all = true; } if (!all) seg.push_back({ 0, n, n }); sort(seg.begin(), seg.end(), [&](constauto& x, constauto& y) { return x[0] == y[0] ? x[1] > y[1] : x[0] < y[0]; });
vector<int> stk; for (int i = 0; i < seg.size(); i++) { auto& [l, r, len] = seg[i]; while (!stk.empty() && l >= seg[stk.back()][1]) { // 这里是 while,弹出所有兄弟,调了好久 stk.pop_back(); } if (!stk.empty()) { // 记录一下真实的贡献是几个节点 seg[stk.back()][2] -= r - l - 1; } stk.push_back(i); }
ll res = 1; for (auto [l, r, len] : seg) { res = res * Catalan(len - 1) % mod; } cout << res << endl; }