Codeforces Round #796 (Div. 2)A~D

115 篇文章 3 订阅
42 篇文章 2 订阅
本文探讨了Cirno的Perfect Bitmasks Classroom中关于低位操作的算法问题,以及Patchouli的Magical Talisman涉及的奇偶性和向量操作。同时,Manipulating History章节展示了如何通过编程处理历史数据,而The Enchanted Forest则聚焦于数据处理和优化问题。
摘要由CSDN通过智能技术生成

A. Cirno’s Perfect Bitmasks Classroom

在这里插入图片描述

void solve()
{
	cin>>n;
	int res=lowbit(n);
	if(n<3)cout<<3<<endl;
	else 
	{
		if(res==n)cout<<res+1<<endl;
		else cout<<res<<endl;
	}
}

B. Patchouli’s Magical Talisman

在这里插入图片描述

void solve()
{
	cin>>n;
	int a=0,b=0;
	vector<int>v;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		if(x%2)a++;
		else b++,v.pb(x);
	}
	if(a)cout<<b<<endl;
	else
	{
		int res=INF;
		for(auto x:v)
		{
			int k=0;
			while(x%2==0)
			{
				x/=2;
				k++;
			}
			res=min(res,k);
		}
		res+=b-1;
		cout<<res<<endl;
	}
}

C. Manipulating History

在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
const int N=500010;
int n,m;
int w[N];
struct node
{
	int l,r;
	int sum,lmax,rmax,tmax;//区间和,前缀max,后缀max,区间max 
}tr[4*N];
void pushup(node &u,node &l,node &r)
{
	u.sum=l.sum+r.sum;
	u.lmax=max(l.lmax,l.sum+r.lmax);
	u.rmax=max(r.rmax,r.sum+l.rmax);
	u.tmax=max(max(l.tmax,r.tmax),l.rmax+r.lmax);
}
void pushup(int u)
{
	pushup(tr[u],tr[u<<1],tr[u<<1|1]);
}
void build(int u,int l,int r)
{
	if(l==r)tr[u]={l,r,w[r],w[r],w[r],w[r]};
	else
	{
		tr[u]={l,r};
		int mid=l+r>>1;
		build(u<<1,l,mid),build(u<<1|1,mid+1,r);
		pushup(u);
	}
}
void modify(int u,int x,int v)
{
	if(tr[u].l==x&&tr[u].r==x)tr[u]={x,x,v,v,v,v};
	else
	{
		int mid=tr[u].l+tr[u].r>>1;
		if(x<=mid)modify(u<<1,x,v);
		else modify(u<<1|1,x,v);
		pushup(u);
	}
}
node query(int u,int l,int r)
{
	if(tr[u].l>=l&&tr[u].r<=r)return tr[u];
	else
	{
		int mid=tr[u].l+tr[u].r>>1;
		if(r<=mid)return query(u<<1,l,r);
		else if(l>mid)return query(u<<1|1,l,r);
		else
		{
			auto left=query(u<<1,l,r);
			auto right=query(u<<1|1,l,r);
			node res;
			pushup(res,left,right);
			return res;
		}
	}
}
void solve()
{
	cin>>n;
	map<char,int>mp;
	for(int i=0;i<2*n;i++)
	{
		string s;
		cin>>s;
		for(auto x:s)mp[x]++;
	}
	string s;
	cin>>s;
	for(auto x:s)mp[x]++;
	for(auto x:mp)
	{
		if(x.y%2)cout<<x.x;
	}
	cout<<endl;
}
signed main()
{
	io;
	cin>>_;
	while(_--)
	solve();
	return 0;
}

D. The Enchanted Forest

在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,m;
const int N=2e5+10;
int s[N];
void solve()
{
	cin>>n>>m;
	int res=0;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		s[i]=s[i-1]+x;
	}
	if(m>=n)
	{
		res+=s[n]+m-n+(n-1)*(m-n+1+m-1)/2;
		cout<<res<<endl;
	}
	else
	{
		for(int i=1;i+m-1<=n;i++)
			res=max(res,s[i+m-1]-s[i-1]);
		res+=(m-1)*m/2;
		cout<<res<<endl;
	}
}
signed main()
{
	io;
	cin>>_;
	while(_--)
	solve();
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

leimingzeOuO

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值