Codeforces Round #816 (Div. 2)参考代码

A. Crossmarket

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
using namespace std;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;

inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
    return x*f;
}

void solve()
{
	int n=read(),m=read();
	if(n==1&&m==1)
	{
		printf("0\n");
		return;
	}
	if(m>n)swap(n,m);
	printf("%d\n",n-1+m-1+m);
}

int main()
{
	int T=read();
	while(T--)solve();
	return 0;
}

B. Beautiful Array

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
using namespace std;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;

inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
    return x*f;
}

void solve()
{
	ll n,k,b,s;
	scanf("%lld%lld%lld%lld",&n,&k,&b,&s);
	if(k*b>s||k*b+n*(k-1)=b*k&&s

C. Monoblock

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
using namespace std;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;

inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
    return x*f;
}
const int N=1e5+10;
ll a[N];
void solve()
{
	ll n,q;
	scanf("%lld%lld",&n,&q);
	for(int i=1;i<=n;i++)scanf("%lld\n",&a[i]);
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=a[i-1])ans+=i*(n-i+1);
		else ans+=n-i+1;
	}
	while(q--)
	{
		int i=read(),x=read();
		ll yy=0;
		if(a[i]==a[i-1])yy+=n-i+1;
		else yy+=i*(n-i+1);
		if(a[i]==a[i+1])yy+=n+1-(i+1);
		else yy+=(i+1)*(n+1-(i+1));
		ll zz=0;
		if(x==a[i-1])zz+=n-i+1;
		else zz=i*(n-i+1);
		if(x==a[i+1])zz+=n+1-(i+1);
		else zz+=(i+1)*(n+1-(i+1));
		ans+=zz-yy;
		a[i]=x;
		printf("%lld\n",ans);
	}
}

int main()
{
	int T=1;
	while(T--)solve();
	return 0;
}

D. 2+ doors

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
using namespace std;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;

inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
    return x*f;
}
const int N=1e5+10;
bool a[N][31],mark[N][31];
int ans[N];
vectorv[N][30];
void solve()
{

	int n=read(),q=read();
	while(q--)
	{
		int x=read(),y=read(),z=read();
		if(x==y)
		{
			for(int i=29;i>=0;i--)
			{
				if((z>>i)&1)a[x][i]=1;
				else mark[x][i]=mark[y][i]=1;
			}
			continue;
		}
		for(int i=29;i>=0;i--)
		{
			if((z>>i)&1)
			{
				v[x][i].push_back(y);
				v[y][i].push_back(x);
			}
			else mark[x][i]=mark[y][i]=1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=29;j>=0;j--)
		{
			if(mark[i][j])
			{
				for(int id=0;id=0;j--)
		{
			if(!a[i][j])
			{
				for(int id=0;id

你可能感兴趣的:(题解,CF,c++,图论,算法)