首页 > 其他分享 >Codeforces Round #875 (Div. 2)

Codeforces Round #875 (Div. 2)

时间:2023-05-29 11:25:04浏览次数:54  
标签:const int res rhs 875 Codeforces using return Div

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

相关文章

  • Codeforces Round 875 (Div. 2) A~D
    CodeforcesRound875(Div.2)A~DA.TwinPermutations构造\(a[i]+b[i]=n+1\)voidwork(){ intn; cin>>n; rep(i,1,n){ intx; cin>>x; cout<<n-x+1<<""; } cout<<endl;}B.Arraymerging......
  • HTML中让上下两个div之间保持一定距离或没有距离
    这篇文章主要为大家详细介绍了HTML让上下两个DIV之间保持一定距离或没有距离,可以用来参考一下。1、若想上下DIV块之间距离,只需设定:在CSS里设置DIV标签各属性参数为0div{margin:0;border:0;padding:0;}这里就设置了DIV标签CSS属性相当于初始化了DIV标签CSS属性,这里设置margin外......
  • Educational Codeforces Round 149 (Rated for Div. 2)(A~F)
    A.GrasshopperonaLine题意:给出n,k,从0开始,每次可以加一个数,最快到达n需要,输出首先跳几次,然后每次跳多少,限制只有一个跳的长度不能整除k。分析:n%k,有余直接跳,没余数,先跳一个,再跳剩余的长度。代码:#include<cstring>#include<iostream>#include<algorithm>usingnamespac......
  • 29. Divide Two Integers刷题笔记
    参考的题解classSolution:defdivide(self,dividend:int,divisor:int)->int:positive=(dividend<0)is(divisor<0)dividend,divisor=abs(dividend),abs(divisor)res=0whiledividend>=divisor:......
  • Codeforces 1444E - Finding the Vertex
    非常神秘的一道题,当之无愧的*3500。首先考虑转化题意。考虑一种决策树,由于我们每次问一条边之后,相当于会根据信息删掉两个连通块中的一个,因此一种决策树实际上对应了原树的一棵边分树。而为了让最坏情况下的询问次数最少,我们目标实际上是最小化边分树的深度。考虑借鉴P5912JA......
  • Educational Codeforces Round 149 (Rated for Div. 2) 题解
    https://codeforces.com/contest/1837https://codeforces.com/contest/1837/problems利益相关:上紫祭。真的不要以为这道题放在F就不敢做。压线过题的感觉真好。ABC题都过水,就不写了。代码丢在这里:A:https://codeforces.com/contest/1837/submission/207156920B:https:......
  • 用fetch处理的流,放到div中会有样式丢失的问题
    最近在做fetch处理流的问题,发现接收到得流,在div中渲染得时候样式会丢失,特别是空格、换行之类得。为了解决问题去看看了css得样式处理发现css中有个属性white-space。然后就去看了这个属性的定义和取值情况。   在css中white-space属性用来控制容器的文本中带有空白符、制表......
  • 文字超过div容器的高度显示...
    我们一般遇到的场景为超过一行或者2行,3行等等显示...,但是对于div容器如果想实现超过div容器的高度才显示...,这该怎么实现呢我们知道,当div只有内部只有一个文字时此时空间足够,2个也是...那么第n个呢,所以思路来了,我们可以一直计算下去,知道超过容器高度为止代码如下:<html><bod......
  • CodeForces 1107B Digital root(找规律)
    传送门每个数字都有个数位和,就是把数字的每一位相加直到数位和是一个个位数。然后题目就要你求第K个数位和为X的数字是多少。写一些数字出来就很容易发现规律了可以看出每一竖列的数位和是相等的,然后就找到规律是9*(k-1)+x,注意数据范围是1e12,是longlong,然后就这么多,就可以直......
  • CodeForces 1107A Digits Sequence Dividing(思维)
    传送门唉,题目讲的天花乱坠的,花里胡哨,一上来真是把我唬住了。愣了半天也没看出来到底咋做,后来借助翻译明白了这个题就是让你把一串字符分成两串,然后第一串要比第二串小,就这样,然后又是个SpecialJudge。做的时候就把第一个数作为第一个串,然后串长如果为2,就判断一下后面的串要比第一个......