We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c50ad83 commit 17d68efCopy full SHA for 17d68ef
cc.cpp
@@ -0,0 +1,26 @@
1
+// Coodinate Compression
2
+// https://youtu.be/fR3W5IcBGLQ?t=8550
3
+template<typename T=int>
4
+struct CC {
5
+ bool initialized;
6
+ vector<T> xs;
7
+ CC(): initialized(false) {}
8
+ void add(T x) { xs.push_back(x);}
9
+ void init() {
10
+ sort(xs.begin(), xs.end());
11
+ xs.erase(unique(xs.begin(),xs.end()),xs.end());
12
+ initialized = true;
13
+ }
14
+ int operator()(T x) {
15
+ if (!initialized) init();
16
+ return upper_bound(xs.begin(), xs.end(), x) - xs.begin() - 1;
17
18
+ T operator[](int i) {
19
20
+ return xs[i];
21
22
+ int size() {
23
24
+ return xs.size();
25
26
+};
0 commit comments