template <class T> class heap { vector<T>data; public: heap() {} heap(T *a,int len) { for (int i = 0; i < len; i++) data.push(a[i]); } T top() { return data.front(); } //为了方便操作,索引从1开始,所以为了完全填充数组,查询时偏移一位 void push(T x) { data.emplace_back(x); int now = data.size(); while (now > 1) { if (data[now - 1] < data[(now >> 1) - 1]) swap(data[now - 1], data[(now >> 1) - 1]); now >>= 1; } } void pop() { data.front() = data.back(); int len = data.size() - 1; int now = 2; while (now <=len) { if (data[now] < data[now - 1])now++; if (data[now - 1] < data[(now >> 1) - 1]) { swap(data[now - 1], data[(now >> 1) - 1]); now <<= 1; } else break; } data.pop_back(); } int size() { return data.size(); } };