QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#391480#7245. Frank SinatraSiilhouetteCompile Error//C++143.4kb2024-04-16 16:42:362024-04-16 16:42:37

Judging History

你现在查看的是最新测评结果

  • [2024-04-16 16:42:37]
  • 评测
  • [2024-04-16 16:42:36]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include<set>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

#define bel(x) ((x-1)/(block)+1)
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;

const int N=200010;
int n,m,k,block,ans,a[N],c[N],realans[N],vis[N];
struct Query{
	int l,r,id,x;
	inline bool operator <(const Query &that){
		return bel(l)==bel(that.l)?bel(l)&1?
			r<that.r : r>that.r : l<that.l;
	}
}q[N];

inline int g()
{
	int res=0,fix=1;
	char ch;
	while(!isdigit(ch=getchar()))
		fix=(ch=='-')?-1:fix;
	do res=res*10+(ch^'0');
	while(isdigit(ch=getchar()));
	return fix*res;
}

inline void out(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)out(x/10);
	putchar(x%10+'0');
}

struct Graph{
	int tot,head[N],tim,st[N],ed[N],suiv[N<<1],ver[N<<1],edge[N],fa[N],siz[N],eu[N],son[N],top[N],d[N];

	inline void lnk(int x,int y,int z)
	{
		ver[++tot]=y;
		edge[tot]=z;
		suiv[tot]=head[x];
		head[x]=tot;
	}

	inline void dfs1(int x,int maxson=-1)
	{
		d[x]=d[fa[x]]+1;
		eu[st[x]=++tim]=x;siz[x]=1;
		for(int i=head[x];i;i=suiv[i])
		{
			int y=ver[i],z=edge[i];
			if(y==fa[x])continue;
			fa[y]=x;a[y]=z;
			dfs1(y);siz[x]+=siz[y];
			if(siz[y]>maxson)
				maxson=siz[y],son[x]=y;
		}
		eu[ed[x]=++tim]=x;
	}

	inline void dfs2(int x,int acro)
	{
		top[x]=acro;
		if(son[x])dfs2(son[x],acro);
		for(int i=head[x];i;i=suiv[i])
		{
			int y=ver[i];
			if(y==fa[x]||y==son[x])continue;
			dfs2(y,y);
		}
	}

	inline int lca(int x,int y)
	{
		while(top[x]^top[y])
		{
			if(d[top[x]]<d[top[y]])swap(x,y);
			x=fa[top[x]];
		}
		if(d[x]>d[y])swap(x,y);
		return x;
	}

}e;

inline void update(int x,int val)
{
	//cout<<"update "<<x<<" "<<val<<endl;
	//if(e.eu[x]==1)return;
	int y=a[e.eu[x]];
	if(!vis[e.eu[x]])
	{
		c[y]++;
		if(c[y]==1&&ans==y)
			while(c[ans])ans++;
	}
	else
	{
		c[y]--;
		if(!c[y]&&y<ans)ans=y;
	}
	vis[e.eu[x]]^=1;
		/*
		if(val==1)
		{
			c[a[x]]++;
			if(c[a[x]]==1&&ans==a[x])
				while(c[ans])ans++;
		}
		else
		{
			c[a[x]]--;
			if(!c[a[x]]&&a[x]<ans)ans=a[x];
		}
		*/
}

int main()
{
	n=g(),m=g();
	for(int i=1,x,y,z;i<n;i++)
	{
		x=g(),y=g(),z=g();
		if(z>n)z=200005;
		e.lnk(x,y,z),e.lnk(y,x,z);
	}
	a[1]=200005;
	e.dfs1(1);
	e.dfs2(1,1);
	sort(b+1,b+1+n);
	//int num=unique(b+1,b+1+n)-b-1;
	//for(int i=1;i<=n;i++)
	//	a[i]=(lower_bound(b+1,b+1+num,a[i])-b)-1;
	
	//for(int i=1;i<=n;i++)
	//	cout<<a[i]<<" ";
	//cout<<endl;

	//for(int i=1;i<=e.tim;i++)
	//	cout<<e.eu[i]<<" ";
	//cout<<endl;

	block=(int)sqrt(n<<1)+1;
	for(int i=1,x,y,l;i<=m;i++)
	{
		x=g(),y=g();
		if(x==y){ realans[i]=0;continue; }
		l=e.lca(x,y);
		//cout<<"lca "<<l<<endl;
		if(e.st[x]>e.st[y])swap(x,y);
		if(l==x)q[i].l=e.st[x],q[i].r=e.st[y],q[i].x=e.st[x];
		else q[i].l=e.ed[x],q[i].r=e.st[y];
		q[i].id=i;
	}
	sort(q+1,q+1+m);
	int l=1,r=0;
	for(int i=1;i<=m;i++)
	{
		//cout<<"i "<<q[i].l<<" "<<q[i].r<<" "<<q[i].id<<endl;
		while(l<q[i].l)update(l++,-1);
		while(l>q[i].l)update(--l,1);
		while(r<q[i].r)update(++r,1);
		while(r>q[i].r)update(r--,-1);
		if(q[i].x)update(q[i].x,1);

		realans[q[i].id]=ans;
		if(q[i].x)update(q[i].x,1);
	}
	for(int i=1;i<=m;i++)
		out(realans[i]),putchar('\n');
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:139:14: error: ‘b’ was not declared in this scope
  139 |         sort(b+1,b+1+n);
      |              ^