AT_abc477_g.Frequency Query on Tree
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a tree with N vertices numbered 1 to N. The i-th edge connects vertex ui and vertex vi. Also, integer xi is written on vertex i.
Process Q queries. In each query, you are given integers s,t,a,b; find the number of integers y satisfying the following condition.
- Let f be the number of vertices with integer y written on them among the vertices on the path connecting vertex s and vertex t. Then, a≤f≤b holds.
给你一棵包含 N 个顶点的树,顶点编号为 1 到 N。第 i 条边连接顶点 ui 和顶点 vi。此外,顶点 i 上写有一个整数 xi。
你需要处理 Q 个查询。对于每个查询,给定整数 s,t,a,b;求满足以下条件的整数 y 的个数:
- 设 f 表示在顶点 s 与顶点 t 之间的路径上,所写整数恰好为 y 的顶点个数,则需满足 a≤f≤b。
输入格式
The input is given from Standard Input in the following format:
N Q
x1 x2 … xN
u1 v1
u2 v2
⋮
uN−1 vN−1
query1
query2
⋮
queryQ
Each query queryq is given in the following format:
s t a b
输入从标准输入中按以下格式给出:
N Q
x1 x2 … xN
u1 v1
u2 v2
⋮
uN−1 vN−1
query1
query2
⋮
queryQ
每个查询 queryq 的格式如下:
s t a b
输出格式
Output Q lines. The q-th line should contain the answer to the q-th query.
输出 Q 行。第 q 行应包含第 q 个查询的答案。
输入输出样例
输入#1
5 4 1 2 3 1 2 1 2 2 3 3 4 4 5 1 5 1 2 1 4 2 3 3 5 1 1 2 4 2 5
输出#1
3 1 3 0
输入#2
11 8 1 2 3 1 4 2 2 5 2 1 2 1 2 1 3 2 4 1 5 4 6 6 7 3 8 7 9 4 10 9 11 8 11 3 5 6 10 1 5 8 9 5 6 1 11 1 4 4 6 2 5 5 6 2 6 3 7 1 1 5 7 5 8
输出#2
1 2 0 1 0 2 1 0
说明/提示
Sample 1 Explanation:
Consider the first query.
The vertices on the path connecting vertex 1 and vertex 5 are, in order, vertex 1, vertex 2, vertex 3, vertex 4, and vertex 5.
The integers written on these vertices are, in order, 1,2,3,1,2. Thus, there are three integers y satisfying the condition: 1,2,3.
Constraints
- 2≤N≤2×105
- 1≤Q≤2×105
- 1≤ui<vi≤N
- The given graph is a tree.
- 1≤xi≤N
- 1≤s<t≤N
- 1≤a≤b≤N
- All input values are integers.
样例 1 解释:
考虑第一个查询。
连接顶点 1 与顶点 5 的路径上的顶点依次为:顶点 1、顶点 2、顶点 3、顶点 4 和顶点 5。
这些顶点上所写的整数依次为 1,2,3,1,2。因此,满足条件的整数 y 共有三个:1,2,3。
约束条件
- 2≤N≤2×105
- 1≤Q≤2×105
- 1≤ui<vi≤N
- 给定图是一棵树。
- 1≤xi≤N
- 1≤s<t≤N
- 1≤a≤b≤N
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?