返回上页
离散化
C++template <class T, const int N>
struct discrete_map {
int len, width; T d[N];
discrete_map() : len(0), width(-1) {memset(d, 0, sizeof(d));}
void clear() {len = 0, width = -1, memset(d, 0, sizeof(d));}
void add(const T& x) {d[++len] = x;}
void operator() () {sort(d + 1, d + len + 1), width = unique(d + 1, d + len + 1) - d - 1;}
int operator[] (const T& x) const {return lower_bound(d + 1, d + width + 1, x) - d;}
T value(int x) const {return d[x];}
};