牛客多校6 B. Eezie and Pie(树上差分+倍增)

题意:每个节点u都会将向1号节点的简单路径上、距离不超过a[u]中的节点+1,求每个节点上最后的值是多少

思路:用倍增思想可以求出某个节点u上走a[u]步的节点编号,然后可以使用树上差分将这一段同时+1,最后跑一遍树上前缀和就能得出答案

​
#include <iostream>
#include <cstring>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int a,b,c,x;
		cin>>a>>b>>c>>x;
		if(c==x){
			puts("Yes");
			continue; 
		} 
		int x1=a-2*b, x2=2*b-a;
		if(a==2*b){
			if(b-c==x||a-b-c==x) puts("Yes");
			else puts("No"); 
		} 
		else{
		if((x-c)%x1==0||(x-b+c)%x1==0)
		puts("Yes");
		else puts("No"); 
		} 
	}
}

​


版权声明:本文为m0_63535901原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。