# Codeforces Round #474 D Full Binary Tree Queries 满二叉树操作

``````#include <bits/stdc++.h>
using namespace std;
const int maxn = 62;
const long long mod = pow(2,62);
long long deep[maxn];
long long real_mod[maxn];
void init(){
real_mod[0] = 1;
for(int i=1;i<maxn;i++)
real_mod[i] = real_mod[i-1] << 1;
}

int main(){
init();
int q,t;
long long x,k;
scanf("%d",&q);
while(q--){
scanf("%d%lld",&t,&x);
int lo = log2(x);//当前层
if(t<3){
scanf("%lld",&k);
k += mod;
if(t==1){
k %= real_mod[lo];
deep[lo] += k; //深度偏移量
deep[lo] %= real_mod[lo]; //取模
}
else {
k %= real_mod[lo];
int tag = 0;
for(int i=lo;i<maxn;i++){ //深度偏移
deep[i] += k * real_mod[i-lo];
deep[i] %= real_mod[i];
}
}
}
else {
long long out,now = x + deep[lo]; //当前点的下标
now %= real_mod[lo]; //当前点的下标
if(x==1){
printf("%lld\n",x);
continue;
}
printf("%lld",x);
now /= 2;
lo--;
for(;lo>=0;lo--){
out = real_mod[lo]+now-deep[lo]; //out当前输出值
out %= real_mod[lo];
printf(" %lld",out+real_mod[lo]);
now /= 2;
}
printf("\n");
}
}
return 0;
}``````

原文作者：满二叉树
原文地址: https://blog.csdn.net/a912952381/article/details/79936496
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。