exam8.3

rank25凉凉好吧。。。。。。
T1:。。。
        一开始完全**
        手玩给的那张图(不放图,我太饿把图吃了)
        发现对于任一个节点,减去上一个比他小的斐波那契数就是父节点,
        于是,欢乐敲代码(话说别人好像是二分查找,而我直接打表+lower_bound,<algorithm>大法好)
        过编译,于是……
        样例死了。绝望.png
        一个小时后,过了。
        结果MLE80好吧。

  代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define int long long
#define cin(a)		scanf("%lld",&a)
#define cout1(a)	printf("%lld
",a)
#define cout2(a)	printf("%lld ",a)
int a[65]={1,1};
int f[600050][65];
int m,n;
void pre()
{
	for(int q=2;q<=64;q++)
		a[q]=a[q-1]+a[q-2];
}
int tot;
int work(int x,int y)
{
	if(x==y)
		return x;
	int dx,dy;
	int tx=x,ty=y;
	int k1=++tot,k2=++tot;
	f[k1][0]=x,f[k2][0]=y;
	for(int q=1;;q++)
	{
		if(tx==1)
		{
			dx=q;
			break;
		}
		int l=lower_bound(a+1,a+64,tx)-a;
		if(tx<=a[l])	--l;
		f[k1][q]=tx-a[l];
		tx-=a[l];
	}
	for(int q=1;;q++)
	{
		if(ty==1)
		{
			dy=q;
			break;
		}
		int l=lower_bound(a+1,a+64,ty)-a;
		if(ty<=a[l])	--l;
		f[k2][q]=ty-a[l];
		ty-=a[l];
	}
	for(int q=0;;q++)
		if(f[k1][dx-q]!=f[k2][dy-q])
				return f[k1][dx-q+1];
}

signed main()
{
	pre();
	cin(m);
	for(int q=1,x,y;q<=m;q++)
	{
		cin(x),cin(y);
		cout1(work(x,y));
	}
}

P.S.如果哪位知道我为什么MLE,欢迎告诉来骂我

updata:已A,可改为滚动数组

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define int long long
#define cin(a)		scanf("%lld",&a)
#define cout1(a)	printf("%lld
",a)
#define cout2(a)	printf("%lld ",a)
int a[100]={1,1};
int f[2][100];
int m,n;
void pre()
{
	for(int q=2;q<=64;q++)
		a[q]=a[q-1]+a[q-2];
}
int tot;
int work(int x,int y)
{
	if(x==y)
		return x;
	int dx,dy;
	memset(f,0,sizeof(f));
	int tx=x,ty=y;
	int k1=0,k2=1;
	f[k1][0]=x,f[k2][0]=y;
	for(int q=1;;q++)
	{
	
		if(tx==1)
		{
			dx=q;
			break;
		}
		int l=lower_bound(a+1,a+64,tx)-a;
		if(tx<=a[l])	--l;
		f[k1][q]=tx-a[l];
		tx-=a[l];
	}
	for(int q=1;;q++)
	{
		if(ty==1)
		{
			dy=q;
			break;
		}
		int l=lower_bound(a+1,a+64,ty)-a;
		if(ty<=a[l])	--l;
		f[k2][q]=ty-a[l];
		ty-=a[l];
	}
	for(int q=0;;q++)
		if(f[k1][dx-q]!=f[k2][dy-q])
				return f[k1][dx-q+1];
}
signed main()
{
	pre();
	cin(m);
	for(int q=1,x,y;q<=m;q++)
	{
		cin(x),cin(y);
		cout1(work(x,y));
	}
}

T2:

  没思路,一点也没有……

  想开权值线段树,感觉MLE稳了

  突然发现修改、撤销、查询全是$ Theta(1) $的,于是高兴了

  带修莫队啊

  不过,怎么打来着……

  没事,现场YY

  成功过样例了。

  结果TLE40

  块长爆了

  过往的人啊,请牢记,带修莫队块长是$n^{  frac {2} {3} }$

  仍是代码:

 

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define cin(a)		scanf("%d",&a)
#define cout1(a)	printf("%d
",a)
#define cout2(a)	printf("%d ",a)
const int maxn=3e5+5;
struct node{
	int l,r,wh,tim,ans;
}a[maxn];
struct cha{
	int k,tim;
}b[maxn];
int tot1,tot2;
int block[maxn];
int t[maxn];
int c[maxn];
int l,r;
int m,n;
inline bool h233(node a,node b)
{
	if(block[a.l]==block[b.l])
			return a.r<b.r;
	return block[a.l]<block[b.l];
}
inline bool h234(cha a,cha b)
{
	return a.tim<b.tim;
}
inline bool h235(node a,node b)
{
	return a.tim<b.tim;
}
inline void work(const int k)
{
	register int bj;
	for(bj=1;;++bj)
	{
		register int p=b[bj].k;
		if(b[bj].tim>a[k].tim||bj>tot2)
			break;
		if(p==r)
			--t[c[p]],++t[c[p+1]];
		if(p==l-1)
			++t[c[p]],--t[c[p+1]];
		c[p]^=c[p+1],c[p+1]^=c[p],c[p]^=c[p+1];
	}
	--bj;
	while(l<a[k].l)	--t[c[l++]];
	while(l>a[k].l)	++t[c[--l]];
	while(r<a[k].r)	++t[c[++r]];
	while(r>a[k].r)	--t[c[r--]];
	a[k].ans=t[a[k].wh];
	for(;bj;--bj)
	{
		int p=b[bj].k;
		if(p==r)
			--t[c[p]],++t[c[p+1]];
		if(p==l-1)
			++t[c[p]],--t[c[p+1]];
		c[p]^=c[p+1],c[p+1]^=c[p],c[p]^=c[p+1];
	}
}
signed main()
{
	cin(n),cin(m);
	int len=1+pow(n,0.666666);
	for(register int q=1;q<=n;++q)
		block[q]=(q-1)/len+1;
	for(register int q=1;q<=n;++q)
		cin(c[q]);
	for(register int q=1,x;q<=m;++q)
	{
		cin(x);
		if(x==1)
		{
			cin(a[++tot1].l),
			cin(a[tot1].r),
			cin(a[tot1].wh);
			a[tot1].tim=q;
		}
		else
		{
			cin(b[++tot2].k);
			b[tot2].tim=q;
		}
	}
	sort(a+1,a+tot1+1,h233);
	sort(b+1,b+tot2+1,h234);
	l=1,r=0;
	for(register int q=1;q<=tot1;++q)
		work(q);
	sort(a+1,a+tot1+1,h235);
	for(register int q=1;q<=tot1;++q)
		cout1(a[q].ans);
}

T3:

   没啥想说的,真没啥想说的,暴力都不会,水8分放弃


于是,结束了。

原文地址:https://www.cnblogs.com/ooovooo/p/11294401.html