问题2143--Tunnels

2143: Tunnels

时间限制: 1Sec 内存限制:256 MB
提交:34 解决:8
[ 状态] [ 讨论版] [ 提交] [命题人: ]
题目描述
There are n holes and n-1 tunnels connecting them. The holes are labeled by 1,2,...,n. For all i>1, a hole number i is connected by a tunnel to the hole number ⌊i/2⌋. Tunnels are all bidirectional.


Initially, all the tunnels are available. There will be m events happened in the tunnel system. The i-th event will change the status of the tunnel between u_i and ⌊u_i/2⌋. If this tunnel is available, it will become unavailable, and if this tunnel is unavailable, it will become available.


Please write a program to support these events, and report the number of pairs i,j(1 <= i < j <= n) that holes i,j are still connected after each event.
输入
The first line of the input contains an integer T(1 <= T <= 5), denoting the number of test cases.


In each test case, there are two integers n,m(2 <= n,m <= 100000) in the first line, denoting the number of holes and the number of events.


For the next m lines, each line contains an integer u_i(2 <= u_i <= n), denoting an event.
输出
For each test case, print m lines. The i-th line contains an integer, denoting the number of connected pairs after the i-th event.
样例输入 Copy
1 9 6 6 4 2 4 4 3
样例输出 Copy
28 13 7 13 7 5
来源/分类