#include #include #include #include #include #include #include #include #include #include using namespace std; struct node{ int cnt; int l; int m; node():cnt(0),l(0),m(0){} bool operator < (const node& x) const{ return cnt < x.cnt; } }; struct val{ node a; node b; val operator +(const val& x){ val ret; priority_queue, less> pq; pq.push(a); pq.push(b); pq.push(x.a); pq.push(x.b); ret.a = pq.top(); pq.pop(); bool ok = false; while(pq.size() && !ok){ if(pq.top().l != ret.a.l){ ok = true; ret.b = pq.top(); }else{ pq.pop(); } } return ret; } }; class seg{ public: vector v; int size; seg(int n){ size = 1; while(size vector compress(vector a, int& size){ auto b = a; sort(b.begin(), b.end()); b.erase( unique(b.begin(), b.end()), b.end()); for(int i=0; i> n; vector a(n); for(int i=0; i