Ternary Tree
题号:NC273393
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

You are given a labeled full ternary tree with depth n, containing labels from 1 to (3^n - 1) / 2, with the root labeled as 1. For a node labeled as x, with a depth not exceeding n-1, its three children nodes are labeled as 3x-1, 3x, and 3x+1.

The tree will undergo m operations in order. Each operation will remove the subtree rooted at node labeled as k (if the node has already been removed, this operation will be ignored). You task is to compute how many nodes remain in the tree after each operations.

输入描述:

The first line contains two single integers n (1\leq n\leq 25) and m (1\leq m\leq 2\times 10^5), representing the depth of the full ternary tree and the number of operations, respectively.
In the next m lines, each line contains a single integer k (1\leq k\leq (3^n - 1) / 2), representing an operation that removes the subtree rooted at node labeled as k.

输出描述:

For each operation, output an integer in a single line that represents the number of nodes remaining in the tree after this operation.
示例1

输入

复制
3 4
13
4
11
3

输出

复制
12
9
9
5

说明

Initially, there are 13 nodes in the full ternary tree: