Skip to content

Instantly share code, notes, and snippets.

@rikuTanide
Last active December 15, 2020 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikuTanide/6f69c7bfef36525ad0bdb1dcb92c5ae3 to your computer and use it in GitHub Desktop.
Save rikuTanide/6f69c7bfef36525ad0bdb1dcb92c5ae3 to your computer and use it in GitHub Desktop.
座標圧縮ライブラリ
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