QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#750800#8235. Top Clusterzhouyuxuan3501Compile Error//C++141.7kb2024-11-15 16:01:042024-11-15 16:01:04

Judging History

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

  • [2024-11-15 16:01:04]
  • 评测
  • [2024-11-15 16:01:04]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#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;
}

Details

answer.code:14:1: error: ‘vector’ does not name a type
   14 | vector<I> c[Mn];
      | ^~~~~~
answer.code: In function ‘void dfs(int, int)’:
answer.code:22:20: error: ‘c’ was not declared in this scope
   22 |         for(auto h:c[l])
      |                    ^
answer.code: In function ‘int lca(int, int)’:
answer.code:35:15: error: ‘log2’ was not declared in this scope
   35 |         int p=log2(h-j+1),s1,s2;
      |               ^~~~
answer.code:36:9: error: ‘s1’ was not declared in this scope; did you mean ‘s’?
   36 |         s1=q[j][p];
      |         ^~
      |         s
answer.code:37:9: error: ‘s2’ was not declared in this scope; did you mean ‘s’?
   37 |         s2=q[h-(1<<p)+1][p];
      |         ^~
      |         s
answer.code: In function ‘int main()’:
answer.code:60:17: error: ‘c’ was not declared in this scope
   60 |                 c[j].push_back({h,w});
      |                 ^
answer.code:107:26: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
  107 |                 printf("%d\n",p);
      |                         ~^    ~
      |                          |    |
      |                          int  long long int
      |                         %lld
answer.code:50:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   50 |         scanf("%d%d",&n,&Q);
      |         ~~~~~^~~~~~~~~~~~~~
answer.code:54:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |                 scanf("%d",&k[i].w);
      |                 ~~~~~^~~~~~~~~~~~~~
answer.code:59:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   59 |                 scanf("%d%d%lld",&j,&h,&w);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
answer.code:92:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   92 |                 scanf("%d%lld",&i,&w);
      |                 ~~~~~^~~~~~~~~~~~~~~~