离散化 Discretization
template<typename T,
int IdFrom=0,
typename OpLs=less<T>,
typename OpEq=equal_to<T>>
struct Dctz {
static OpLs ls;
static OpEq eq;
vector<T> x;
void clear() { x.clear(); }
void add(T v) { x.push_back(v); }
void init() {
sort(x.begin(),x.end(),ls);
x.erase(unique(x.begin(),x.end(),eq),x.end());
}
int size() { return x.size(); }
int id(const T &v) {
return lower_bound(x.begin(),x.end(),v,ls)-x.begin()+IdFrom; }
T& operator[](int id) { return x[id-IdFrom]; };
};
Dctz<> dc;
Next: [模板] 随机数 Random