#include<bits/stdc++.h> #define int long long #define ios ios::sync_with_stdio(0),cin.tie(0); usingnamespace std; int n,L,ans = 0; int seg[1000000] = {0};
voidbuild(int val,int cur){ if(seg[cur]==0){ seg[cur] = val; return; } if(val>seg[cur])build(val, 2*cur+2); elsebuild(val, 2*cur+1); }//建立一個會爆掉的二元樹 voidfunc(int val,int cur){ int up = L,low = 0; if(seg[cur]==val){ ans+=up-low; return; } while(seg[cur]!=val){ if(val>seg[cur]){ low = seg[cur]; cur = 2*cur+2; } else{ up = seg[cur]; cur = 2*cur+1; } } ans+=up-low; }