Codeforces Round #875 (Div. 2)
bilibili: Codeforces Round #875 (Div. 2) 实况 | 完成度 [4.01 / 6]
A
#include <bits/stdc++.h>
using ll = long long;
using uint = unsigned;
using namespace std;
int TestCase;
signed main() {
for (scanf("%d", &TestCase); TestCase--;) {
int n;
scanf("%d", &n);
vector<int> a(n);
for (int &x : a) scanf("%d", &x);
for (int i = 0; i < n; ++i) {
printf("%d%c", n - a[i] + 1, " \n"[i == n - 1]);
}
}
return 0;
}
B
#include <bits/stdc++.h>
using ll = long long;
using uint = unsigned;
using namespace std;
int TestCase;
signed main() {
for (scanf("%d", &TestCase); TestCase--;) {
int n;
scanf("%d", &n);
vector<int> a(n), b(n);
for (int &x : a) scanf("%d", &x);
for (int &x : b) scanf("%d", &x);
vector<int> t(2 * n + 100, 0);
int ans = 0;
for (int len = 0, i = 0; i < n; ++i) {
++len;
if (i == 0 || a[i] != a[i - 1]) len = 1;
ans = max(ans, len);
t[a[i]] = max(t[a[i]], len);
}
for (int len = 0, i = 0; i < n; ++i) {
++len;
if (i == 0 || b[i] != b[i - 1]) len = 1;
// ans = max(ans, len);
ans = max(ans, len + t[b[i]]);
}
printf("%d\n", ans);
}
return 0;
}
C(1A)
#include <bits/stdc++.h>
using ll = long long;
using uint = unsigned;
using namespace std;
int TestCase;
signed main() {
for (scanf("%d", &TestCase); TestCase--;) {
int n;
scanf("%d", &n);
vector<vector<pair<int, int>>> G(n);
vector<int> drawn(n, 0), mp(n, 0);
for (int i = 1; i < n; ++i) {
int u, v;
scanf("%d%d", &u, &v);
--u, --v;
G[u].emplace_back(v, i);
G[v].emplace_back(u, i);
}
set<int> all;
drawn[0] = 1;
function<void(int)> access = [&](int u) {
for (auto [v, id] : G[u])
if (!drawn[v]) all.emplace(id), mp[id] = v;
};
int total = 1;
access(0);
for (int cur = 0; all.size(); ) {
auto it = all.lower_bound(cur);
if (it == end(all)) it = all.lower_bound(0), ++total;
cur = *it;
drawn[mp[cur]] = 1;
access(mp[cur]);
all.erase(cur);
}
printf("%d\n", total);
}
return 0;
}
D(1B)
#include <bits/stdc++.h>
using ll = long long;
using uint = unsigned;
using namespace std;
int TestCase;
signed main() {
for (scanf("%d", &TestCase); TestCase--;) {
int n;
scanf("%d", &n);
vector<int> a(n), b(n);
for (int &x : a) scanf("%d", &x);
for (int &x : b) scanf("%d", &x);
// a[i] * a[j] = b[i] + b[j] <= 2 * n
const int top = 2 * n;
vector<unordered_map<int, ll>> all(n * 2 + 10);
for (int i = 0; i < n; ++i) ++all[a[i]][b[i]];
ll ans = 0;
for (int x = 1; x * x <= top && x <= n; ++x)
for (int y = x + 1; y <= n && x * y <= top; ++y) {
int val = x * y;
// printf("x = %d, y = %d\n", x, y);
if (all[x].size() < all[y].size()) {
for (auto [v1, cnt] : all[x])
if (all[y].find(val - v1) != end(all[y])) ans += (ll)cnt * all[y][val - v1];
} else {
for (auto [v1, cnt] : all[y])
if (all[x].find(val - v1) != end(all[x])) ans += (ll)cnt * all[x][val - v1];
}
// printf("ans = %lld\n", ans);
}
for (int x = 1; x * x <= top && x <= n; ++x) {
int val = x * x;
for (auto [v, cnt] : all[x])
if (v * 2 == val) {
ans += (ll)cnt * (cnt - 1) / 2;
} else if (v < val - v && all[x].find(val - v) != end(all[x])) ans += (ll)cnt * all[x][val - v];
// printf("x = %d, ans = %lld\n", x, ans);
}
printf("%lld\n", ans);
}
return 0;
}
// ?????????????????????????????????????????????????????????
E(1C)(补)
#include <bits/stdc++.h>
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;
constexpr int mod = 998244353;
// assume -mod <= x < 2mod
int normZ(int x) {
if (x < 0) x += mod;
if (x >= mod) x -= mod;
return x;
}
template <typename T> T qpow(T x, ll k) {
T res = 1;
for (; k; k >>= 1, x *= x)
if (k & 1) res *= x;
return res;
}
struct Z {
int x;
Z(int x = 0) : x(normZ(x)) {}
Z(ll x) : x(normZ(x % mod)) {}
int val() const { return x; }
Z operator-() const { return Z(normZ(mod - x)); }
Z inv() const {
assert(x != 0);
return qpow(*this, mod - 2);
}
Z &operator*=(const Z &rhs) {
x = (ll)x * rhs.x % mod;
return *this;
}
Z &operator+=(const Z &rhs) {
x = normZ(x + rhs.x);
return *this;
}
Z &operator-=(const Z &rhs) {
x = normZ(x - rhs.x);
return *this;
}
Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }
friend Z operator*(const Z &lhs, const Z &rhs) {
Z res = lhs;
res *= rhs;
return res;
}
friend Z operator+(const Z &lhs, const Z &rhs) {
Z res = lhs;
res += rhs;
return res;
}
friend Z operator-(const Z &lhs, const Z &rhs) {
Z res = lhs;
res -= rhs;
return res;
}
friend Z operator/(const Z &lhs, const Z &rhs) {
Z res = lhs;
res /= rhs;
return res;
}
};
const int mxn = 6e5 + 10;
Z fct[mxn], inv[mxn], ift[mxn];
Z C(int n, int m) {
if (n < m || m < 0) return 0;
return fct[n] * ift[m] * ift[n - m];
}
int TestCase, n, k;
// [l1, r1], [l2, r2]
// => [l1, l2), [l2, r1], (r1, r2]
// < ( > )
// 对于相交的区间,可以拆分成三个区间,如上
// 最后会得到一堆不相交但包含的线段
// dp 上去,时间复杂度总线段数,基本上不超过 2n, 4n
// < ---- ---- ----> f[cur] = G(empty) * f[sub interval], G(n) 长度为 n 的括号序列的方案数
Z Cat(int n) {
return C(2 * n, n) * inv[n + 1];
}
ull a[mxn];
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
signed main() {
fct[0] = inv[0] = ift[0] = fct[1] = inv[1] = ift[1] = 1;
for (int i = 2; i <= 6e5 + 3; ++i) {
fct[i] = fct[i - 1] * i;
inv[i] = inv[mod % i] * (mod - mod / i);
ift[i] = ift[i - 1] * inv[i];
}
for (scanf("%d", &TestCase); TestCase--;) {
scanf("%d%d", &n, &k);
fill(a, a + n + 1, 0);
for (int i = 1; i <= k; ++i) {
int l, r; scanf("%d%d", &l, &r);
ull x = rng();
a[l] ^= x, a[r + 1] ^= x;
}
map<ull, int> cnt;
for (int i = 1; i <= n; ++i) {
a[i] ^= a[i - 1];
++cnt[a[i]];
}
Z ans = 1;
for (auto [_, v] : cnt) ans *= (v & 1 ? Z(0) : Cat(v / 2));
printf("%d\n", ans.val());
}
return 0;
}
标签:const,int,res,rhs,875,Codeforces,using,return,Div
From: https://www.cnblogs.com/lingfunny/p/17439904.html