QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#622021#8235. Top ClusterniolleCompile Error//C++232.4kb2024-10-08 19:30:092024-10-08 19:30:11

Judging History

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

  • [2024-10-08 19:30:11]
  • 评测
  • [2024-10-08 19:30:09]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dwn(i,a,b) for(int i=a;i>=b;i--)
#define lowbit(x) (x&(-x))
#define MAXN 502501
#define int long long
#define mp(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-') f=-1; ch=getchar();}
	while('0'<=ch && ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return x*f;
}
int dfn[MAXN],cnt,n,m,a[MAXN],w[MAXN],p[MAXN][20],pos[MAXN],lg[MAXN],K;
ll D[MAXN];
vector<pair<int,ll> > v[MAXN];
int get(int x,int y){
	if(dfn[x] < dfn[y]) return x;
	return y;
}

int lca(int x,int y){
	if(x == y) return x;
	x = dfn[x], y = dfn[y];
	if(x > y) swap(x,y);
	int k = lg[y - x];
	x++;
	return get(p[x][k], p[y - (1<<k) + 1][k]);
}
void dfs(int x,int y){
	dfn[x] = ++cnt;
	p[x][0] = y;
	for(auto tmp : v[x]){
		int u = tmp.first;
		ll z = tmp.second;
		if(u == y) continue;
		D[u] = D[x] + z;
		dfs(u,x);
	}
}
int L[MAXN],R[MAXN];
ll calc(int x,int y){
	if(x == y) return 0;
	int z = lca(x,y);
	ll res = D[x] + D[y] - D[z] * 2;
	return res;
}
void pre(){
	lg[0] = -1;
	rep(i,1,n) lg[i] = lg[i/2] + 1;
	rep(j,1,19){
		rep(i,1,n) p[i][j] = get(p[i][j-1], p[min(i+(1<<(j-1)),n)][j-1]);
	}
	if(!K) return;
	L[0] = R[0] = pos[0];
	rep(i,1,K-1){
		if(calc(L[i-1],R[i-1]) < calc(L[i-1],pos[i]) && calc(pos[i],R[i-1]) < calc(L[i-1],pos[i])){
			L[i] = L[i-1];
			R[i] = pos[i];
		}
		else if(calc(L[i-1],R[i-1]) < calc(pos[i],R[i-1])){
			L[i] = pos[i];
			R[i] = R[i-1];
		}
		else{
			L[i] = L[i-1];
			R[i] = R[i-1];
		}
	}
}
int main(){
	n = read(); m = read();
	rep(i,1,n) a[i] = read();
	rep(i,1,n) if(a[i] <= n) pos[a[i]] = i;
	while(pos[K]) ++K;
	rep(i,1,n-1){
		int x = read(), y = read(),z = read();
		v[x].emplace_back(y,z);
		v[y].emplace_back(x,z);
	}
	dfs(1,0);
	pre();
//	rep(i,0,K-1) cout<<L[i] << " ";cout<<endl;
//	rep(i,0,K-1) cout<<R[i] << " "; cout<<endl;
	if(!K){
		rep(i,1,m){
			int x = read();
			puts("0");
		}
		return 0;
	}
	rep(i,1,m){
		int x = read();
		ll k; scanf("%lld",&k);
		int l = 0, r = K-1;
		if(calc(pos[0],x) > k){
			puts("0");
			continue;
		}
		while(l < r){
			int mid = (l+r+1) >> 1;
			if(max(calc(L[mid], x), calc(R[mid],x)) <= k)  l = mid;
			else r = mid - 1;
		}
		printf("%d\n",l+1);
	}
	return 0;
}

Details

cc1plus: error: ‘::main’ must return ‘int’
answer.code: In function ‘int main()’:
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",l+1);
      |                         ~^    ~~~
      |                          |     |
      |                          int   long long int
      |                         %lld
answer.code:97:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   97 |                 ll k; scanf("%lld",&k);
      |                       ~~~~~^~~~~~~~~~~