#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
usingnamespace std; using i64 = longlong; using u32 = unsigned; using u64 = unsignedlonglong; using pii = std::pair<int, int>;
constexprint N = 2e5 + 10; constexprint MOD = 998244353;
voidsolve(){ int n, k; cin >> n >> k; vector<int> p(n); for (int i = 0; i < n; ++i) cin >> p[i]; ranges::sort(p, greater<int>()); i64 res = p[0] % MOD; for (int l = 1, r = k - 1; r < n; l = r + 1, r += k - 1) { int ok = 1; for (int i = l; i <= r; ++i) { if (!p[i]) { ok = 0; break; } } if (!ok) break; for (int i = l; i <= r; ++i) { res = res * p[i] % MOD; } } cout << res << "\n"; }
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
usingnamespace std; using i64 = longlong; using u32 = unsigned; using u64 = unsignedlonglong; using pii = std::pair<int, int>;
constexprint N = 3e5 + 10; constexprint MOD = 998244353;
voidsolve(){ int n, m; cin >> n >> m; vector<set<int>> e(n + 1); vector<int> d(n + 1), stk(n + 1), p(n + 1); int top = 0; for (int i = 0, u, v; i < m; ++i) { cin >> u >> v; e[u].insert(v); e[v].insert(u); } for (int i = 1; i <= n; ++i) cin >> p[i]; for (int i = 1; i <= n; ++i) d[i] = e[i].size(); stk[++top] = p[1]; for (int v : e[p[1]]) d[v]--; vector<tuple<int, int>> ans; ans.reserve(n); for (int i = 2; i <= n; ++i) { while (top && d[stk[top]] == 0) { top--; } if (!top) { stk[++top] = p[i]; for (int v : e[p[i]]) d[v]--; continue; } if (!e[stk[top]].contains(p[i])) { ans.push_back({stk[top], p[i]}); } for (int v : e[p[i]]) d[v]--; stk[++top] = p[i]; } cout << ans.size() << "\n"; for (auto [x, y] : ans) cout << x << " " << y << "\n"; }
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)