4fd800b3a8 2011-02-23 kinaba: //------------------------------------------------------------- 4fd800b3a8 2011-02-23 kinaba: // ID Assignment 4fd800b3a8 2011-02-23 kinaba: // 4fd800b3a8 2011-02-23 kinaba: // Verified by 4fd800b3a8 2011-02-23 kinaba: // - ACM/ICPC Tokyo 2010 A 4fd800b3a8 2011-02-23 kinaba: // - SRM 491 Div1 LV3 4fd800b3a8 2011-02-23 kinaba: //------------------------------------------------------------- 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: template<typename T> 4fd800b3a8 2011-02-23 kinaba: class IdGen 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: map<T, int> v2id_; 4fd800b3a8 2011-02-23 kinaba: vector<T> id2v_; 4fd800b3a8 2011-02-23 kinaba: public: 4fd800b3a8 2011-02-23 kinaba: int v2id(const T& v) { 4fd800b3a8 2011-02-23 kinaba: if( !v2id_.count(v) ) { v2id_[v] = size(); id2v_.push_back(v); } 4fd800b3a8 2011-02-23 kinaba: return v2id_[v]; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: const T& id2v(int i) const { return id2v_[i]; } 4fd800b3a8 2011-02-23 kinaba: int size() const { return id2v_.size(); } 4fd800b3a8 2011-02-23 kinaba: };