#include #define INF 1000000001LL #define MOD 1000000007LL #define long long long #define all(x) x.begin(),x.end() using namespace std; struct Node { long value = 0; }; class SegTree { private: vector arr; vector tree; int n; Node trash = {0}; //의미없는 값 입력 Node merge(Node a, Node b) { //여기를 커스텀 구현 Node res; res.value = a.value+b.value; return res; } Node init(int node, int start, int end) { if(start == end) return tree[node] = arr[start]; int mid = (start+end)/2; return tree[node] = merge(init(node*2,start,mid),init(node*2+1,mid+1,end)); } Node query(int node, int start, int end, int left, int right) { if(start > right || end < left) return trash; if(start >= left && end <= right) return tree[node]; int mid = (start+end)/2; return merge(query(node*2,start,mid,left,right),query(node*2+1,mid+1,end,left,right)); } Node update(int node, int start, int end, int index, long l) { if(start > index || end < index) return tree[node]; if(start == end) { tree[node].value+=l; return tree[node]; } int mid = (start+end)/2; return tree[node]=merge(update(node*2,start,mid,index,l),update(node*2+1,mid+1,end,index,l)); } public: void init(int l) { n = l; arr = vector(n); tree = vector(4*n); } void init(vector a) { n = a.size(); arr = a; tree = vector(4*n); init(1,0,n-1); } void init(vector a) { n = a.size(); arr = vector(n); for(int i = 0; i(4*n); init(1,0,n-1); } long query(int left, int right) { if(left > right) return 0; return query(1,0,n-1,left,right).value%MOD; } void update(int index, long val) { update(1,0,n-1,index,val); } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector arr(n); vector sortArr(n); for(int i = 0; i> arr[i]; sortArr[i] = arr[i]; } sort(all(sortArr)); SegTree hapL; hapL.init(n); SegTree cntL; cntL.init(n); SegTree hapR; hapR.init(n); SegTree cntR; cntR.init(n); for(int i = 0; i