Codeforces Round #576 (Div. 2)

RANK:641    1632 → 1681

A:

模拟 暴力扫一遍就出来了  注意边界  time:  0:11

#include 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair pii;
typedef pair pll;
typedef pair pdd;
#define F first
#define S second
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ld PI=acos(-1);
const ld eps=1e-9;
const ll MOD=ll(1e9+7);
const int M = 1e5 + 10;
//unordered_mapmp;
int a[M];
int main()
{
	int n,x,y;
	cin>>n>>x>>y;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	bool f=true;
	int pos;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=y+i&&j<=n;j++)
		if(a[i]>=a[j])
		f=false;
		for(int j=i-1;j<=i-x&&j>=1;j--)
		if(a[i]>=a[j])f=false;
		if(f)
		{
			printf("%d\n",i);
			return 0;
		}
		f=true;
	}
	printf("%d\n",n);
   	return 0;
}
 
 

B:初中几何数学   time:0:16

#include 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair pii;
typedef pair pll;
typedef pair pdd;
#define F first
#define S second
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ld PI=acos(-1);
const ld eps=1e-9;
const ll MOD=ll(1e9+7);
const int M = 1e5 + 10;
//unordered_mapmp;
int main()
{
	double H,L;
	cin>>H>>L;
	printf("%.13f\n",(L*L-H*H)/(2.0*H));
   	return 0;
}

C:阅读理解题  time:01:13

要明白n*k=I*8  看清楚每个变量代表什么,

然后可以求出最大可能的K,(注意加个判断,防K爆int)

然后sort,从前往后扫不同数区间长度K,找到不同数最多的区间。

#include 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair pii;
typedef pair pll;
typedef pair pdd;
#define F first
#define S second
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ld PI=acos(-1);
const ld eps=1e-9;
const ll MOD=ll(1e9+7);
const int M = 4e5 + 10;
int a[M];
map s;
int sum[M];
void solve()
{
	int n,L;
    cin>>n>>L;
    int m=n;
    int dd=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        s[a[i]]++;
        if(s[a[i]]==1)
            dd++;
    }
    int num=0;
    double k=1.0*8*L/n;
    double kk=log(1.0*dd)/log(2);
    if(k>kk)
    {
        printf("0\n");
        return ;
    }
    sort(a+1,a+1+n);
    n=unique(a+1,a+1+n)-(a+1);
    int w=floor(k);
    num=1<

D:这一题线段树想法很自然,区间覆盖tag,加上单点更新mx。每次更新都下推tag标记,查询输出的时候取tag[o]和mx[o]最大。

因为tag[o]=-1时,说明该位置再进行最后一次1操作后没有2操作了(因为1操作会下推2操作。)。如果tag[o]!=-1,说明该位置进行1操作后又进行了2操作,取后来进行的所有2操作中的最大值与mx[o]比较即可。

 

由线段树写法我们发现,每个位置的值只与1操作后的2操作有关,(因为之前的2操作被1强制覆盖了)。所以我们只需要记录后缀2操作,dp思想,和最后一次进行的1操作即可。最后再比较输出就行。

思维写法:

#include 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair pii;
typedef pair pll;
typedef pair pdd;
#define F first
#define S second
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ld PI=acos(-1);
const ld eps=1e-9;
const ll MOD=ll(1e9+7);
const int M = 2e5 + 10;
//unordered_mapmp;
int a[M];
int opt[M];
int x1[M],t1[M],d[M];
int x2[M],t2[M];
int m2[M];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)x1[i]=-1,x2[i]=-1;
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	int m;
	scanf("%d",&m);
	int pre=0;
	int c1=0,c2=0;
	for(int i=1;i<=m;i++)
	{
		int c;
		scanf("%d",&c);
		if(c==1)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			a[x]=y;
			x1[x]=i;
			d[x]=y;
		}
		else
		{
			int x;
			scanf("%d",&x);
			x2[i]=x;
		}
	}
	m2[m+1]=-1;
	for(int i=m;i>=1;i--)
		m2[i]=max(m2[i+1],x2[i]);
	for(int i=1;i<=n;i++)
	{
		if(x1[i]==-1)
            a[i]=max(a[i],m2[1]);//wu 1
        else
            a[i]=max(a[i],m2[x1[i]]);//you 1  qu2  zuida 
	}
    printf("%d",a[1]);
    for(int i=2;i<=n;i++)
        printf(" %d",a[i]);
    printf("\n");
   	return 0;
}
 

线段树写法

#include 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair pii;
typedef pair pll;
typedef pair pdd;
#define F first
#define S second
#define ls o * 2
#define rs o * 2 + 1
#define mid (l + r) / 2
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ld PI=acos(-1);
const ld eps=1e-9;
const ll MOD=ll(1e9+7);
const int M = 2e5 + 10;
int a[M];
int mx[M<<2];
int tag[M<<2];
void pushdown(int o)
{
	if(tag[o]!=-1)
	{
		tag[ls]=max(tag[o],tag[ls]);
		tag[rs]=max(tag[o],tag[rs]);
		tag[o]=-1;
	}
}
void up(int o,int l,int r,int p,int x)
{
	if(l==r)
	{
		mx[o]=x;
		tag[o]=-1;
		return ;
	}
	pushdown(o);
	if(p<=mid)up(ls,l,mid,p,x);
	else up(rs,mid+1,r,p,x);
}
void qu(int o,int l,int r)
{
	if(l==r)
	{
		printf("%d ",max(mx[o],tag[o]));
		return ;
	}
	pushdown(o);
	qu(ls,l,mid);
	qu(rs,mid+1,r);
}
int main()
{
	int n,m,opt,p,x;
	cin>>n;
	memset(tag,-1,sizeof(tag));
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]),up(1,1,n,i,a[i]);
	cin>>m;
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&opt);
		if(opt==1)
		{
			scanf("%d%d",&p,&x);
			up(1,1,n,p,x);
		}
		else
		{
			scanf("%d",&x);
			tag[1]=max(tag[1],x);
		}
	}
	qu(1,1,n);
   	return 0;
}

E:F待补&&&

 

你可能感兴趣的:(CF)