首页 > 其他分享 >Codeforces Round 892 (Div. 2)题解记录

Codeforces Round 892 (Div. 2)题解记录

时间:2024-10-18 16:44:38浏览次数:1  
标签:892 return 题解 ll Codeforces cin x% include mod

题目链接:https://codeforces.com/contest/1859

A. United We Stand


选最大的数即可注意题目输出格式

	#include<iostream>
	#include<string.h>
	#include<map>
	#include<vector>
	#include<set>
	#include<unordered_set>
	#include<stack>
	#include<queue>
	#include<algorithm>
	#include<time.h>
	#include<random>
	#include<string>
	#include<string.h>
	#include<cctype>
	using namespace std;
	typedef int ll;
	mt19937 rnd(time(0));
	const ll mod = 1e9 + 7;
	void fio()
	{
		ios::sync_with_stdio(0);
		cin.tie(0);
		cout.tie(0);
	}
	ll gcd(ll x, ll y)
	{
		if (y == 0)
			return x;
		else
			return gcd(y, x % y);
	}
	ll ksm(ll x, ll y)
	{
		ll ans = 1;
		while (y)
		{
			if (y & 1)
				ans = ans%mod*(x%mod)%mod;
			x = x%mod*(x%mod)%mod;
			y >>= 1;
		}
		return ans%mod%mod;
	}
	ll a[2005];
	int main()
	{
		ll t;
		cin>>t;
		while(t--)
		{
			ll n;
			cin>>n;
			ll cnt=0;
			for(ll i=1;i<=n;i++)
			{
				cin>>a[i];
				if(a[i]==a[1])cnt++;
			}
			if(cnt==n)cout<<-1<<endl;
			else 
			{
				sort(a+1,a+1+n);
				cnt=0;
				for(ll i=1;i<=n;i++)if(a[i]==a[n])cnt++;
				cout<<n-cnt<<" "<<cnt<<endl;
				for(ll i=1;i<=n;i++)
				{
					if(a[i]!=a[n])
					cout<<a[i]<<" ";
				}
				cout<<endl;
				for(ll i=1;i<=n;i++){
					if(a[i]==a[n])
					cout<<a[n]<<" ";
				}
				cout<<endl;
			}
		}
	}

B. Olya and Game with Arrays


翻译有点难看,意思对于每个数组最多可以转移一个数到其他的数组
首先所有数组中的最小元素一定会拿,所以就找第二小的最小值,然后都丢到那个数组去即可

		#include<iostream>
		#include<string.h>
		#include<map>
		#include<vector>
		#include<set>
		#include<unordered_set>
		#include<stack>
		#include<queue>
		#include<algorithm>
		#include<time.h>
		#include<random>
		#include<string>
		#include<string.h>
		#include<cctype>
		using namespace std;
		typedef long long  ll;
		mt19937 rnd(time(0));
		const ll mod = 1e9 + 7;
		void fio()
		{
			ios::sync_with_stdio(0);
			cin.tie(0);
			cout.tie(0);
		}
		ll gcd(ll x, ll y)
		{
			if (y == 0)
				return x;
			else
				return gcd(y, x % y);
		}
		ll ksm(ll x, ll y)
		{
			ll ans = 1;
			while (y)
			{
				if (y & 1)
					ans = ans%mod*(x%mod)%mod;
				x = x%mod*(x%mod)%mod;
				y >>= 1;
			}
			return ans%mod%mod;
		}
		ll a[250005];
		set<pair<ll,ll>>q[250000];
		int main()
		{
			ll t;
			cin>>t;
			while(t--)
			{
				ll n;
				cin>>n;
				ll ans=0;
				for(ll j=1;j<=n;j++)//模拟折返点
				{
					ll cnt=0;
					ll u=0;
					for(ll k=1;k<j;k++)
					{
						cnt+=k*k;
						u=max(u,k*k);
					}
					for(ll k=j;k<=n;k++)
					{
						cnt+=k*(n-k+j);
						u=max(u,k*(n-k+j));
					}
					ans=max(ans,cnt-u);
				}
				cout<<ans<<endl;
			}
		}

C. Another Permutation Problem

题目数据范围小,模拟所有折返点即可

		#include<iostream>
		#include<string.h>
		#include<map>
		#include<vector>
		#include<set>
		#include<unordered_set>
		#include<stack>
		#include<queue>
		#include<algorithm>
		#include<time.h>
		#include<random>
		#include<string>
		#include<string.h>
		#include<cctype>
		using namespace std;
		typedef long long  ll;
		mt19937 rnd(time(0));
		const ll mod = 1e9 + 7;
		void fio()
		{
			ios::sync_with_stdio(0);
			cin.tie(0);
			cout.tie(0);
		}
		ll gcd(ll x, ll y)
		{
			if (y == 0)
				return x;
			else
				return gcd(y, x % y);
		}
		ll ksm(ll x, ll y)
		{
			ll ans = 1;
			while (y)
			{
				if (y & 1)
					ans = ans%mod*(x%mod)%mod;
				x = x%mod*(x%mod)%mod;
				y >>= 1;
			}
			return ans%mod%mod;
		}
		ll a[250005];
		set<pair<ll,ll>>q[250000];
		int main()
		{
			ll t;
			cin>>t;
			while(t--)
			{
				ll n;
				cin>>n;
				ll ans=0;
				for(ll j=1;j<=n;j++)//模拟折返点
				{
					ll cnt=0;
					ll u=0;
					for(ll k=1;k<j;k++)
					{
						cnt+=k*k;
						u=max(u,k*k);
					}
					for(ll k=j;k<=n;k++)
					{
						cnt+=k*(n-k+j);
						u=max(u,k*(n-k+j));
					}
					ans=max(ans,cnt-u);
				}
				cout<<ans<<endl;
			}
		}

D. Andrey and Escape from Capygrad


维护最大位置,用栈带着排好顺序的数跑,如果维护的最大位置<=此时位置那就丢出stack在这个最大位置,剩下的小于\(a[i]\)且没加入\(stack\)的
就不用变位置

		#include<iostream>
		#include<string.h>
		#include<map>
		#include<vector>
		#include<set>
		#include<unordered_set>
		#include<stack>
		#include<queue>
		#include<algorithm>
		#include<time.h>
		#include<random>
		#include<string>
		#include<string.h>
		#include<cctype>
		using namespace std;
		typedef long long  ll;
		mt19937 rnd(time(0));
		const ll mod = 1e9 + 7;
		void fio()
		{
			ios::sync_with_stdio(0);
			cin.tie(0);
			cout.tie(0);
		}
		ll gcd(ll x, ll y)
		{
			if (y == 0)
				return x;
			else
				return gcd(y, x % y);
		}
		ll ksm(ll x, ll y)
		{
			ll ans = 1;
			while (y)
			{
				if (y & 1)
					ans = ans%mod*(x%mod)%mod;
				x = x%mod*(x%mod)%mod;
				y >>= 1;
			}
			return ans%mod%mod;
		}
		map<ll,ll>g1,g2;
		map<ll,ll>k;
		set<ll>f;
		struct s
		{
			ll x,y;
		}p[850000];
		ll a[850000];
		ll ans[850000];
		bool cmp(s x,s y)
		{
			return x.x<y.x;
		}
		int main()
		{
			fio();
			ll t;
			cin>>t;
			while(t--)
			{
				ll n;
				cin>>n;
				g1.clear();
				f.clear();
				k.clear();
				for(ll i=1;i<=n;i++)
				{
					ll l1,r1,a1,b1;
					cin>>l1>>r1>>a1>>b1;
					g1[l1]=max(g1[l1],b1);
					k[l1]++;//大左边界
					f.insert(r1);
					f.insert(l1);
					f.insert(b1);
				}
				ll oi=0;
				for(auto j:f)
				{
					oi++;
					a[oi]=j;
				}
				ll uo;
				cin>>uo;
				for(ll i=1;i<=uo;i++)
				{
					ll ko;
					cin>>ko;
					p[i].x=ko,p[i].y=i;
				}
				sort(p+1,p+1+uo,cmp);
				ll po=1;
				ll cnt=0;
				stack<pair<ll,ll>>cf;
				for(ll i=1;i<=oi;i++)
				{
					if(i==1)
					{
						while(p[po].x<a[i]&&po<uo+1)
						{
							ans[p[po].y]=p[po].x;
							po++;
						}
						if(k[a[i]]>0)
						{
							cnt=max(cnt,g1[a[i]]);
						}
						while(p[po].x<=cnt&&po<uo+1)
						{
							cf.push({p[po].x,p[po].y});
							po++;
						}
						if(cnt==a[i])
						{
							while(!cf.empty())
							{
								ans[cf.top().second]=cnt;
								cf.pop();
							}
						}
					}
					else if(i==oi)//大右边界
					{
						//cout<<cf.size()<<endl;
						if(cnt<a[i])
						{
						while(p[po].x<a[i]&&po<uo+1)
						{
							ans[p[po].y]=p[po].x;
							po++;
						}
						while(!cf.empty())
							{
								ans[cf.top().second]=cnt;
								cf.pop();
							}
						}
						//cout<<cf.size()<<endl;
						if(k[a[i]]>0)
						{
							cnt=max(cnt,g1[a[i]]);
						}
						while(p[po].x<=cnt&&po<uo+1)
						{
							cf.push({p[po].x,p[po].y});
							po++;
						}
						if(cnt==a[i])
						{
							while(!cf.empty())
							{
								ans[cf.top().second]=cnt;
								cf.pop();
							}
						}
						while(po<uo+1)
						{
							ans[p[po].y]=p[po].x;
							po++;
						}
					}
					else if(i!=oi)
					{
						//cout<<po<<endl;
						if(cnt<a[i])
						{
						while(p[po].x<a[i]&&po<uo+1)
						{
							ans[p[po].y]=p[po].x;
							po++;
						}
						while(!cf.empty())
							{
								ans[cf.top().second]=cnt;
								cf.pop();
							}
						}
						//cout<<po<<endl;
						//cout<<p[po].x<<endl;
						/*if(a[i]==16)
						{
							cout<<cf.size()<<endl;
							cout<<po<<endl;
						}*/
						if(k[a[i]]>0)
						{
							cnt=max(cnt,g1[a[i]]);
						}
						//cout<<a[i]<<endl;
						while(p[po].x<=cnt&&po<uo+1)
						{
							cf.push({p[po].x,p[po].y});
							po++;
						}
						//cout<<po<<endl;
						if(cnt==a[i])
						{
							while(!cf.empty())
							{
								ans[cf.top().second]=cnt;
								cf.pop();
							}	
						}
					}
				}
				for(ll i=1;i<=uo;i++)cout<<ans[i]<<" ";
				cout<<endl;
			}
		}

标签:892,return,题解,ll,Codeforces,cin,x%,include,mod
From: https://www.cnblogs.com/cjcf/p/18474575

相关文章

  • P5025 [SNOI2017] 炸弹 题解
    题意link.题解一个好想一点的正解。考虑到可能连锁爆炸,我们不能通过一个单纯的二分来解决问题。考虑dp。记\(f(i)\)为第\(i\)个点爆炸,最远能引爆到哪个坐标小于它的点。\(g(i)\)为第\(i\)个点爆炸,最远能引爆到哪个坐标大于它的点。我们以\(f\)为例,\(g\)可以通......
  • AT_nikkei2019_2_qual_c 题解
    blog。不会做结论题,怎么办???不会做结论题,怎么办???不会做结论题,怎么办???不妨对\(b\)排序,将\(a\)对应到相应的位置。那么题目有两个条件:#1:\(\foralla_i\leb_i\)。#2:操作限制。注意到\(n-1\)次操作就能完成对\(a\)排序。所以用\(n-2\)次操作可以将\(a\)变成一个Almos......
  • P9351 [JOI 2023 Final] Maze 题解
    Description给定一张\(R\timesC\)的地图,其中.可以走,而#不能走。一次操作可以将\(N\timesN\)的正方形范围内所有点变成.,给定起点和终点,求最少需要几次操作使得起点和终点连通(只能上下左右移动)。\(R\timesC\le6\times10^6\),\(N\leR\leC\)。Solution先考虑怎么......
  • CF571B-题解
    CF571B题意给定数组\(A\)和值\(k\),你可以重排\(A\)中的元素,使得\(\displaystyle\sum_{i=1}^{n-k}|A_i-A_{i+k}|\)最小。输出最小值。思路\(A_i,A_{i+k}\)就等同于在将\(i\)模\(k\)的意义上把\(A\)分为若干组贪心的想要使\(\displaystyle\sum_{i=1}^{n-k}|A_i-A......
  • 【题解】Solution Set - NOIP2024集训Day56 哈希杂题
    【题解】SolutionSet-NOIP2024集训Day56哈希杂题https://www.becoder.com.cn/contest/5640「CF568C」NewLanguage做过的2-sat。「NOI2024」集合做过。做法见提交记录。「CSP-S2022」星战简要题意:给定有向图。修改使一条边失效/恢复;使一个点的所有入边......
  • [YDOI R1] Necklace 题解
    题目传送门前置芝士二项式定理:\((a+b)^n=\sum\limits_{i=0}^{n}C^i_n\timesa^i\timesb^{n-i}\)快速幂Meaning有\(n\)种珠子,每种有\(a_i\)颗,且美丽值为\(v_i\)。任意两颗珠子不同(同种类也算不同)。每种珠子有一个漂亮值\(v_i\)。项链有一个美丽度,若第\(i\)种珠子......
  • Codeforces Round 893 (Div. 2)题解记录
    题目链接:https://codeforces.com/contest/1858A.Buttons从自身角度出发,我想赢就得保证我的按钮尽可能多所以,大家都优先按\(c\),然后分析先后顺序即可 #include<iostream> #include<string.h> #include<map> #include<vector> #include<set> #include<unordered_set> #......
  • [ABC134F] Permutation Oddness 题解
    [ABC134F]PermutationOddness题解朴素的想法显然是状压dp,枚举选择的子集,但复杂度不可接受。考虑优化。注意到对于\(p_i\),它的贡献只会有两种可能性,\(+p_i,-p_i\)。于是初步的想法是按照\(p_i\)的正负性选择分类。考虑到对于相同正负性的选择\(p\),其是等价的。于是我们......
  • P4229 某位歌姬的故事 题解
    P4229某位歌姬的故事题解\(n\le9\times10^8\),显然复杂度不与\(n\)相关。\(m\le500\),显然可以接受\(O(Tm^2)\)的做法。对于\([l,r]\),考虑套路地将端点离散化,使得复杂度只和关键点个数有关。考虑对于\([l,r,m]\),离散化后被分成了\(a_1,a_2,\cdots,a_p\)段,那么这些段的......
  • ZZJC新生训练赛第四场题解
    ZZJCACM新生训练赛-2024.10.16题目难度Easy(简单):B,C,D,GMedium(中等):A,EAnti-AK(防AK):EC题解题思路A页既可以是彩印也可以是黑白印,B页只能是彩印,所以只要比较A页彩印和A页黑白印的价格高低就好。因为a,b,x,y最大都是1e9,用int直接相乘的话会爆掉,所以......