首页 > 其他分享 >Codeforces Round 919 (Div. 2)(A~D) 题解

Codeforces Round 919 (Div. 2)(A~D) 题解

时间:2024-01-15 13:00:14浏览次数:35  
标签:cnt ch 题解 ll len Tex 919 MAXN Div

Codeforces Round 919 (Div. 2) (A~D)题解

A. Satisfying Constraints

题意:给你一些条件让你求出满足条件的整数有多少个。

模拟即可。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 2e5+5;
ll Tex = 1, n;
void AC(){
	cin >> n;
	ll l = 1, r = 1e9;
	vector<ll> p;
	unordered_map<ll, ll> mp;
	for(int i = 1; i <= n; i ++){
		ll a, x;
		cin >> a >> x;
		if(a == 1) l = max(l, x);
		else if(a == 2) r = min(r, x);
		else p.push_back(x);
	}
	if(l > r) cout << 0 << endl;
	else{
		ll ans = r - l + 1;
		for(int i = 0; i < p.size(); i ++)
			if(p[i] >= l && p[i] <= r && !mp[p[i]]) ans --, mp[p[i]] = 1;
			cout << ans << endl;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin >> Tex;
	while(Tex --) AC();
	return 0;
}

B. Summation Game

题意:给你一个序列, \(ALice\) 删掉一些数后,\(Bob\) 将一些数变为负数,求最后所有数之和最大能变成多少。

前缀和一下然后每个位置讨论即可。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 4e5+5;
ll Tex = 1, n, x, y, a[MAXN], s[MAXN];
void AC(){
	cin >> n >> x >> y;
	memset(s, 0, sizeof s);
	ll ans = - 1e14;
	if(x >= n) ans = 0;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i ++)
		s[i] = s[i - 1] + a[i];
	for(int i = max(1ll, n - x); i <= n; i ++)
		ans = max(ans, s[i] - 2 * (s[i] - s[max(i - y, 0ll)]));
	cout << ans << endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin >> Tex;
	while(Tex --) AC();
	return 0;
}

C. Partitioning the Array

赛时写了粗心特判 \(1\) 的时候放在输入前面了,找半天错误,掉大分呜呜。

对于每一组 \(a_1 \% m == a_{k + 1} \% m\) 那么 \(|a_1 - a_{k + 1}| \% m == 0\) 。

其实就是找所有对应相邻位置上的数之差的绝对值最大公因数是否为 \(1\) ,为 \(1\) 则找不到。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 2e5+5;
ll Tex = 1, n, a[MAXN], ans;
void check(ll x){
	ll GGcd = 0;
	for(int i = 1; i <= x; i ++){
		ll Gcd = 0;
		for(int k = x + i; k <= n; k += x)
			Gcd = __gcd(Gcd, abs(a[k] - a[k - x]));
		GGcd = __gcd(GGcd, Gcd);
		if(GGcd == 1) return;
	}
	ans ++;
}
void AC(){
	cin >> n;
	ans = 0;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	if(n == 1){
		cout << 1 << endl;
		return;
	}
	for(int i = 1; i <= sqrt(n); i ++){
		if(n % i == 0){
			check(i);
			if(n / i != i) check(n / i);
		}
	}
	cout << ans << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin >> Tex;
	while(Tex --) AC();
	return 0;
}

D. Array Repetition

发现最终数组不能超过 \(10^{18}\) ,超过了后面的操作就没有意义。

开一个结构体数组记录每次新加的数,上一次的数组长度 和 当前数组的长度,每次进行操作 \(2\) 时候就记录下一个,如果数组长度大于 \(10^{18}\) 就不管了,不再进行任何操作,后面操作都无效。

对于每次查询操作,二分查找属于哪一次操作里面,然后 \(dfs\) 查找值。

#include<bits/stdc++.h>
using namespace std;
typedef __int128 ll;
const ll MAXN = 105;
ll Tex, n, q, opt, x;
vector<ll> Len;
struct node{
	vector<ll> in;
	ll len, tmp;
	node(){
		in.clear();
		len = 0, tmp = 0;
	}
	bool operator < (const node & p) const {return len < p.len;}
}a[MAXN];
inline ll read(){
	ll x = 0, f = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-') ch = getchar();
	if(ch == '-') f = -1, ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return f * x;
}
inline void print(ll x){
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + '0');
}
void dfs(ll x){
	ll idx = lower_bound(Len.begin(), Len.end(), x) - Len.begin();
	ll mod = a[idx].tmp + a[idx].in.size();
	ll real = x % mod == 0 ? mod : x % mod;
	if(real <= a[idx].tmp) dfs(real);
	else print(a[idx].in[real - a[idx].tmp - 1]), putchar(' ');
}
void AC(){
	n = read(); q = read();
	Len.clear();
	for(int i = 0; i < 80; i ++){
		a[i].in.clear();
		a[i].len = 0;
		a[i].tmp = 0;
	}
	Len.push_back(0);
	ll cnt = 1, p = 0;
	for(int i = 1; i <= n; i ++){
		opt = read(); x = read();
		if(p) continue;
		if(opt == 1) a[cnt].in.push_back(x);
		else{
			a[cnt].len = (a[cnt].tmp + a[cnt].in.size()) * (x + 1);
			Len.push_back(a[cnt].len);
			if(a[cnt].len > 1e18) p = 1;
			cnt ++;
			a[cnt].tmp = a[cnt - 1].len;
		}
	}
	a[cnt].len = a[cnt].tmp + a[cnt].in.size();
	Len.push_back(a[cnt].len);
	while(q --){
		x = read();
		dfs(x);
	}
	putchar('\n');
}
int main(){
	Tex = read();
	while(Tex --) AC();
	return 0;
} 

标签:cnt,ch,题解,ll,len,Tex,919,MAXN,Div
From: https://www.cnblogs.com/XiaoMo247/p/17965145

相关文章

  • element-forge在Linux Centos中打包构建时遇到的异常问题解决方案
    环境:LinuxCentOS8x64electron:27.1.0electron-forge:7.1.0electrondev依赖包"devDependencies":{"@electron-forge/cli":"^7.1.0","@electron-forge/maker-deb":"^7.1.0","@electron-forge/maker-rpm&quo......
  • P10058 Reverse and Rotate题解
    简单题意一共3个操作:rev:将字符串翻转。>\(x\):将后面\(x\)个字母移到前面。<\(x\):将前面\(x\)个字母移到后面。解法解法一看到#1到#3的范围可以打出暴力程序,按题意模拟,时间复杂度\(O(n|S|)\)。预计\(30\)pts。解法二很明显,第二个操作和第三个操作有点像......
  • 洛谷比赛【LGR-171-Div.3】深圳科创学院基础赛 #7 &「RHOI」Round 2 赛后总结
    洛谷比赛【LGR-171-Div.3】深圳科创学院基础赛#7&「RHOI」Round2赛后总结比赛链接:https://www.luogu.com.cn/contest/146495建议先看原题再看文章。A-Water(P10056)有\(n\)个杯子,每个杯子的容积是\(a\),且初始装有\(b\)体积水。你可以进行任意次操作,每次操作选择任......
  • Codeforces Round 919 (Div. 2)
    CodeforcesRound919(Div.2)A-SatisfyingConstraints#include<bits/stdc++.h>#defineendl'\n'#defineintlonglongusingnamespacestd;constintN=1e6+10;voidsolve(){ intn; intl=-1; intr=1e9+10; cin>>......
  • CF-1920-div2 总结
    1.结果赛时做出:AB(D)赛后做出:CD评分变化:1535->1500rank:45212.赛后总结>1个人评价这次比赛是我寒假的第一次,昨天坐了一天的动车,虽然平稳,但还是有晕车,导致晚上状态不好,个人因素还是有的。最主要的因素还是后一个小时太晕了,D题有个小问题没发现。除此之外,近期开始服用的药物让......
  • P9816 少项式复合幂 题解
    题目链接:少项式复合幂注意到题目的模并不是很大,我们考虑两个核心的性质。\(f(f(x))\bmodp=f(f(x)\bmodp)\bmodp\),证明直接代入\(f(x)\)进去得到:\(f(f(x))=a_0\timesf^0(x)+a_1\timesf^1(x)...+a_n\timesf^n(x)\bmodp=\)\[\sum_{i=0}^{n}a_i\timesf^{i}(x)\b......
  • P5501 [LnOI2019] 来者不拒,去者不追 题解
    题目链接:来者不拒,去者不追直接在线查询题目所给的式子是很困难的,我们考虑单点考察贡献。对于一个已经确定的式子,我们发现加入一个数或者删除一个数的贡献如图所示:如图所示,在原有的序列为\((1,2,3)\)当中,我们加入新的\(2\)进去,我们观察到每个数的贡献的变化是这样,比\(2\)......
  • quasar <q-page>下面<div>自动计算height的问题
    由于要解决adsense引起的CLSissue,根据https://web.dev/articles/optimize-cls?utm_source=lighthouse&utm_medium=lr给出的建议,在广告的container上加上min-height。<divv-if="$q.platform.is.mobile"class="adsenseunitdetai......
  • 题解 P7169 [eJOI2020 Day1] Exam
    传送门。题意有两个长度为\(N\)的数列\(A_i\),\(B_i\)。可以对\(A\)数组进行若干次操作,每次可以使\(A_i\)到\(A_j\)中的所有数变成期间的最大值,求最多能使多少个数满足要求。分析显然,要使我们的某一个\(A_x\)变成\(B_x\),至少会包含\(A_{L_x}\)或\(A_{R_x}\),\(L_......
  • P5321 [BJOI2019] 送别 题解--zhengjun
    由于大家的做法需要大量分类讨论和代码量,这里提供一种不怎么分类的,容易实现的做法。首先,由于墙体会随时变化,所以直接对墙体本身维护不是很方便。我们可以牺牲一点常数,对\((i,j)\)建立四个点\(UL_{i,j},UR_{i,j},DL_{i,j},DR_{i,j}\)分别表示\((i-\varepsilon,j-\varepsilo......