QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#750808#8235. Top Clusterzhouyuxuan3501Compile Error//C++141.7kb2024-11-15 16:02:172024-11-15 16:02:17

Judging History

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

  • [2024-11-15 16:02:17]
  • 评测
  • [2024-11-15 16:02:17]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<vector>
#define L long long
using namespace std;
const int Mn=1e6+11;
struct I
{
	int h,w;
	bool operator<(const I& k)const
	{
		return w<k.w;
	}
}k[Mn],D[Mn];
vector<I> c[Mn];
int n,Q,S[Mn],q[Mn][21],s,E[Mn],z;
L g[Mn];
void dfs(int l,int F)
{
	S[l]=S[F]+1;
	q[++s][0]=l;
	E[l]=s;
	for(auto h:c[l])
	{
		if(h.h==F)continue;
		g[h.h]=g[l]+h.w;
		dfs(h.h,l);
		q[++s][0]=l;
	}
}
int lca(int j,int h)
{
	j=E[j];
	h=E[h];
	if(j>h)swap(j,h);
	int p=log2(h-j+1),s1,s2;
	s1=q[j][p];
	s2=q[h-(1<<p)+1][p];
	if(S[s1]<S[s2])return s1;
	return s2;
}
L Gd(int j,int h)
{
	int p=lca(j,h);
	return g[j]+g[h]-g[p]-g[p];
}
int main()
{
	int i,j,h,s1,s2,A,B;
	L w,p;
	scanf("%d%d",&n,&Q);
	for(i=1;i<=n;i++)
	{
		k[i].h=i;
		scanf("%d",&k[i].w);
	}
	sort(k+1,k+n+1);
	for(i=1;i<n;i++)
	{
		scanf("%d%d%lld",&j,&h,&w);
		c[j].push_back({h,w});
		c[h].push_back({j,w});
	}
	dfs(1,0);
	for(i=1;i<21;i++)
		for(h=1;h+(1<<(i-1))<=s;h++)
		{
			s1=q[h][i-1];
			s2=q[h+(1<<(i-1))][i-1];
			q[h][i]=(S[s1]<S[s2])?s1:s2;
		}
	for(i=1;i<=n;i++)if(k[i].w!=i-1){z=i-1;break;}
	D[1]={k[1].h,k[1].h};
	for(i=2;i<=n;i++)
	{
		D[i]=D[i-1];
		w=Gd(D[i].h,D[i].w);
		p=Gd(D[i-1].h,k[i].h);
		if(p>w)
		{
			w=p;
			D[i]={D[i-1].h,k[i].h};
		}
		p=Gd(D[i-1].w,k[i].h);
		if(p>w)
		{
			w=p;
			D[i]={D[i-1].w,k[i].h};
		};
	}
	while(Q--)
	{
		scanf("%d%lld",&i,&w);
		A=1;B=n;h=n+1;
		while(A<=B)
		{
			j=(A+B)>>1;
			p=max(Gd(D[j].h,i),Gd(D[j].w,i));
			if(p>w)
			{
				h=j;
				B=j-1;
			}
			else A=j+1;
		}
		p=z;
		if(h!=n+1)p=min(p,1LL*k[h].w);
		printf("%d\n",p);
	}
	return 0;
}

详细

answer.code: In function ‘int lca(int, int)’:
answer.code:36:15: error: ‘log2’ was not declared in this scope
   36 |         int p=log2(h-j+1),s1,s2;
      |               ^~~~
answer.code:37:9: error: ‘s1’ was not declared in this scope; did you mean ‘s’?
   37 |         s1=q[j][p];
      |         ^~
      |         s
answer.code:38:9: error: ‘s2’ was not declared in this scope; did you mean ‘s’?
   38 |         s2=q[h-(1<<p)+1][p];
      |         ^~
      |         s
answer.code: In function ‘int main()’:
answer.code:61:35: warning: narrowing conversion of ‘w’ from ‘long long int’ to ‘int’ [-Wnarrowing]
   61 |                 c[j].push_back({h,w});
      |                                   ^
answer.code:62:35: warning: narrowing conversion of ‘w’ from ‘long long int’ to ‘int’ [-Wnarrowing]
   62 |                 c[h].push_back({j,w});
      |                                   ^
answer.code:108:26: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
  108 |                 printf("%d\n",p);
      |                         ~^    ~
      |                          |    |
      |                          int  long long int
      |                         %lld
answer.code:51:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |         scanf("%d%d",&n,&Q);
      |         ~~~~~^~~~~~~~~~~~~~
answer.code:55:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |                 scanf("%d",&k[i].w);
      |                 ~~~~~^~~~~~~~~~~~~~
answer.code:60:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |                 scanf("%d%d%lld",&j,&h,&w);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
answer.code:93:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   93 |                 scanf("%d%lld",&i,&w);
      |                 ~~~~~^~~~~~~~~~~~~~~~