[c++] Segment Tree
For every two numbers a,b (a<b), we want a+b==T. \n1, if T in [2,a], need two steps;\n2, if T in (a,a+b), need one step;\n3, if T in (a+b, b+limit], need one st
For every two numbers a,b (a<b), we want a+b==T. \n1, if T in [2,a], need two steps;\n2, if T in (a,a+b), need one step;\n3, if T in (a+b, b+limit], need one step \n4, if T in (b+limit, 2* limit], need two steps \nFor every pair, we update the range.\nThen find the T which has smallest total steps. \n\n```cpp \nclass Solution {\npublic:\n    int seg[200001<<2];\n    int minMoves(vector<int>& nums, int limit) {\n        int n=nums.size();\n        for(int i=0;i<n/2;i++){\n            int a=nums[i];\n            int b=nums[n-1-i];\n            if(a>b) swap(a,b);\n            update(0,0,200000,2,a,2);\n            update(0,0,200000,a+1,a+b-1,1);\n            update(0,0,200000,a+b+1,b+limit,1);\n            update(0,0,200000,b+limit+1,2*limit,2);\n        }\n        int res=INT_MAX;\n        for(int i=2;i<=2*limit;i++){\n            search(0,0,200000,i);\n            res=min(res,t);\n        }\n        return res;\n    }\n    \n    int t;\n    void search(int idx, int left, int right, int sidx){\n        if(left>right || sidx>right || sidx<left) return ;\n        if(left==right){\n            t=seg[idx];\n            return ;\n        }\n        if(seg[idx]>0){\n            seg[idx*2+1]+=seg[idx];\n            seg[idx*2+2]+=seg[idx];\n            seg[idx]=0;\n        }\n        int mid=(left+right)/2;\n        search(idx*2+1,left,mid,sidx);\n        search(idx*2+2,mid+1,right,sidx);\n    }\n    \n    void update(int idx, int left, int right, int uleft, int uright, int val){\n        if(left>right || uleft>right || uright<left) return ;\n        if(uleft<=left && uright>=right){\n            seg[idx]+=val;\n            return ;\n        }\n        \n        if(seg[idx]>0){\n            seg[idx*2+1]+=seg[idx];\n            seg[idx*2+2]+=seg[idx];\n            seg[idx]=0;\n        }\n        int mid=(left+right)/2;\n        update(idx*2+1,left,mid,uleft,uright,val);\n        update(idx*2+2,mid+1,right,uleft,uright,val);\n    }\n};\n```
[]