A8158 | Half-decay tree
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Recently Petya has become keen on physics. Anna V., his teacher noticed Petya's interest and gave him a fascinating physical puzzle — a half-decay tree.
A half-decay tree is a complete binary tree with the height $h$ . The height of a tree is the length of the path (in edges) from the root to a leaf in the tree. While studying the tree Petya can add electrons to vertices or induce random decay with synchrophasotron. Random decay is a process during which the edges of some path from the root to the random leaf of the tree are deleted. All the leaves are equiprobable. As the half-decay tree is the school property, Petya will return back the deleted edges into the tree after each decay.
After being desintegrated, the tree decomposes into connected components. Charge of each component is the total quantity of electrons placed in vertices of the component. Potential of desintegerated tree is the maximum from the charges of its connected components. Each time before inducing random decay Petya is curious about the mathematical expectation of potential of the tree after being desintegrated.
A half-decay tree is a complete binary tree with the height $h$ . The height of a tree is the length of the path (in edges) from the root to a leaf in the tree. While studying the tree Petya can add electrons to vertices or induce random decay with synchrophasotron. Random decay is a process during which the edges of some path from the root to the random leaf of the tree are deleted. All the leaves are equiprobable. As the half-decay tree is the school property, Petya will return back the deleted edges into the tree after each decay.
After being desintegrated, the tree decomposes into connected components. Charge of each component is the total quantity of electrons placed in vertices of the component. Potential of desintegerated tree is the maximum from the charges of its connected components. Each time before inducing random decay Petya is curious about the mathematical expectation of potential of the tree after being desintegrated.
输入格式
First line will contain two integers $h$ and $q$ ( $1<=h<=30,1<=q<=10^{5}$ ). Next $q$ lines will contain a query of one of two types:
- add $v$ $e$ Petya adds $e$ electrons to vertex number $v$ ( $1<=v<=2^{h+1}-1,0<=e<=10^{4}$ ). $v$ and $e$ are integers.
The vertices of the tree are numbered in the following way: the root is numbered with 1, the children of the vertex with number $x$ are numbered with $2x$ and $2x+1$ .
- decayPetya induces tree decay.
- add $v$ $e$ Petya adds $e$ electrons to vertex number $v$ ( $1<=v<=2^{h+1}-1,0<=e<=10^{4}$ ). $v$ and $e$ are integers.
The vertices of the tree are numbered in the following way: the root is numbered with 1, the children of the vertex with number $x$ are numbered with $2x$ and $2x+1$ .
- decayPetya induces tree decay.
输出格式
For each query decay solution you should output the mathematical expectation of potential of the tree after being desintegrated. The absolute or relative error in the answer should not exceed $10^{-4}$ .
输入输出样例
输入 #1
1 4 add 1 3 add 2 10 add 3 11 decay
输出 #1
13.50000000
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted