Last active
December 15, 2020 05:46
-
-
Save rikuTanide/6f69c7bfef36525ad0bdb1dcb92c5ae3 to your computer and use it in GitHub Desktop.
座標圧縮ライブラリ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Conv { | |
ll cursor = 0; | |
map<ll, ll> to_short; // <original, small > | |
map<ll, ll> to_long; // <small, original> | |
std::set<ll> tmp; | |
bool build_end = false; | |
void set(ll original) { | |
if (to_short.find(original) != to_short.end()) { | |
return; | |
} | |
to_long[cursor] = original; | |
to_short[original] = cursor; | |
cursor++; | |
} | |
public: | |
ll revert(ll after) { | |
assert(build_end); | |
assert(to_long.find(after) != to_long.end()); | |
return to_long[after]; | |
} | |
ll convert(ll original) { | |
assert(build_end); | |
assert(to_short.find(original) != to_short.end()); | |
return to_short[original]; | |
} | |
ll next() { | |
return cursor; | |
} | |
// 前計算省略のため | |
void cache(ll t) { | |
assert(!build_end); | |
tmp.insert(t); | |
} | |
void build() { | |
assert(!build_end); | |
for (ll t : tmp) { | |
set(t); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment