66 std::array<uint64_t, 2 * k> segtree = {};
68 constexpr int log2() {
return std::ceil(std::log2(k)); }
74 void insert(uint32_t index, uint32_t hash) {
80 segtree[ind] = (uint64_t)~hash << 32 | index;
81 for (
int rep = 0; rep < log2(); rep++) {
82 segtree[ind >> 1] = std::max(segtree[ind], segtree[ind ^ 1]);
87 uint32_t min() {
return segtree[1]; }
89 uint32_t min_hash() {
return ~(segtree[1] >> 32); }
91 void min_syncmer(std::vector<uint32_t> &vec) {
92 if (segtree[1] >> 32 ==
93 std::max(uint32_t(segtree[i] >> 32),
94 uint32_t(segtree[i == k ? 2 * k - 1 : i - 1] >> 32))) {
95 vec.emplace_back(segtree[i]);
99 void min_syncmer(std::vector<std::pair<uint32_t, uint32_t>> &vec) {
100 if (segtree[1] >> 32 ==
101 std::max(uint32_t(segtree[i] >> 32),
102 uint32_t(segtree[i == k ? 2 * k - 1 : i - 1] >> 32))) {
103 vec.emplace_back(segtree[i], ~(segtree[1] >> 32));
115 std::array<uint64_t, k> arr;
120 Naive &operator=(
const Naive &other) =
default;
122 void insert(uint32_t index, uint32_t hash) {
123 arr[i] = (uint64_t)~hash << 32 | index;
130 for (
int j = k - 2; j >= 0; j--) {
131 if (arr[j] > arr[i]) {
138 uint32_t min_hash() {
140 for (
int j = k - 2; j >= 0; j--) {
141 if (arr[j] > arr[i]) {
145 return ~(uint32_t)(arr[i] >> 32);
148 void min_syncmer(std::vector<uint32_t> &vec) {
150 for (
unsigned int l = 1; l < k; l++) {
151 if (arr[l] > arr[j]) {
155 if (arr[j] >> 32 == std::max(uint32_t(arr[i] >> 32),
156 uint32_t(arr[i ? i - 1 : k - 1] >> 32))) {
157 vec.emplace_back(arr[i]);
161 void min_syncmer(std::vector<std::pair<uint32_t, uint32_t>> &vec) {
162 unsigned int j = k - 1;
163 for (
int l = k - 2; l >= 0; l--) {
164 if (arr[l] > arr[j]) {
168 if (arr[j] >> 32 == std::max(uint32_t(arr[i] >> 32),
169 uint32_t(arr[i ? i - 1 : k - 1] >> 32))) {
170 vec.emplace_back(arr[i], ~(uint32_t)(arr[j] >> 32));
183 unsigned int last = 0;
184 std::vector<uint64_t> arr = std::vector<uint64_t>(k);
190 void insert(uint32_t index, uint32_t hash) {
192 arr[i] = (uint64_t)~hash << 32 | index;
194 if (arr[i] > arr[last]) {
196 }
else if (last == i) {
197 for (
unsigned j = 0; j < k; j++) {
198 if (arr[j] > arr[last]) {
208 uint32_t min() {
return arr[last]; }
210 uint32_t min_hash() {
return ~(uint32_t)(arr[last] >> 32); }
212 void min_syncmer(std::vector<uint32_t> &vec) {
213 if (arr[last] >> 32 ==
214 std::max(uint32_t(arr[i] >> 32),
215 uint32_t(arr[i ? i - 1 : k - 1] >> 32))) {
216 vec.emplace_back(arr[i]);
220 void min_syncmer(std::vector<std::pair<uint32_t, uint32_t>> &vec) {
221 if (arr[last] >> 32 ==
222 std::max(uint32_t(arr[i] >> 32),
223 uint32_t(arr[i ? i - 1 : k - 1] >> 32))) {
224 vec.emplace_back(arr[i], ~(uint32_t)(arr[last] >> 32));
234 uint32_t k, i = 0, last = 0;
235 std::vector<uint64_t> arr;
237 Adaptive(uint32_t k) : k(k), arr(k) {}
241 void naive(uint32_t index, uint32_t hash) {
242 arr[i] = (uint64_t)~hash << 32 | index;
247 void naive2(uint32_t index, uint32_t hash) {
249 arr[i] = (uint64_t)~hash << 32 | index;
251 if (arr[i] > arr[last]) {
253 }
else if (last == i) {
254 for (
unsigned j = 0; j < k; j++) {
255 if (arr[j] > arr[last]) {
265 void insert(uint32_t index, uint32_t hash) {
276 for (
int j = k - 2; j >= 0; j--) {
277 if (arr[j] > arr[i]) {
287 uint32_t min_hash() {
290 for (
int j = k - 2; j >= 0; j--) {
291 if (arr[j] > arr[i]) {
295 return ~(uint32_t)(arr[i] >> 32);
297 return ~(uint32_t)(arr[last] >> 32);
301 void min_syncmer(std::vector<uint32_t> &vec) {
303 unsigned int j = k - 1;
304 for (
int l = k - 2; l >= 0; l--) {
305 if (arr[l] > arr[j]) {
310 std::max(uint32_t(arr[i] >> 32),
311 uint32_t(arr[i ? i - 1 : k - 1] >> 32))) {
312 vec.emplace_back(arr[i]);
315 if (arr[last] >> 32 ==
316 std::max(uint32_t(arr[i] >> 32),
317 uint32_t(arr[i ? i - 1 : k - 1] >> 32))) {
318 vec.emplace_back(arr[i]);
323 void min_syncmer(std::vector<std::pair<uint32_t, uint32_t>> &vec) {
325 unsigned int j = k - 1;
326 for (
int l = k - 2; l >= 0; l--) {
327 if (arr[l] > arr[j]) {
332 std::max(uint32_t(arr[i] >> 32),
333 uint32_t(arr[i ? i - 1 : k - 1] >> 32))) {
334 vec.emplace_back(arr[i], ~(uint32_t)(arr[j] >> 32));
337 if (arr[last] >> 32 ==
338 std::max(uint32_t(arr[i] >> 32),
339 uint32_t(arr[i ? i - 1 : k - 1] >> 32))) {
340 vec.emplace_back(arr[i], ~(uint32_t)(arr[last] >> 32));
350 uint32_t k, i = 0, last = 0;
351 std::vector<__uint128_t> arr;
357 void naive(uint32_t index, uint64_t hash) {
358 arr[i] = (__uint128_t)~hash << 32 | index;
363 void naive2(uint32_t index, uint64_t hash) {
365 arr[i] = (__uint128_t)~hash << 32 | index;
367 if (arr[i] > arr[last]) {
369 }
else if (last == i) {
370 for (
int j = k - 1; j >= 0; j--) {
371 if (arr[j] > arr[last]) {
381 void insert(uint32_t index, uint64_t hash) {
385 return naive2(index, hash);
392 for (
int j = k - 2; j >= 0; j--) {
393 if (arr[j] > arr[i]) {
403 uint64_t min_hash() {
406 for (
int j = k - 2; j >= 0; j--) {
407 if (arr[j] > arr[i]) {
411 return ~(uint64_t)(arr[i] >> 32);
413 return ~(uint64_t)(arr[last] >> 32);
417 void min_syncmer(std::vector<uint32_t> &vec) {
419 unsigned int j = k - 1;
420 for (
int l = k - 2; l >= 0; l--) {
421 if (arr[l] > arr[j]) {
426 std::max(uint32_t(arr[i] >> 32),
427 uint32_t(arr[i ? i - 1 : k - 1] >> 32))) {
428 vec.emplace_back(arr[i]);
431 if (arr[last] >> 32 ==
432 std::max(uint32_t(arr[i] >> 32),
433 uint32_t(arr[i ? i - 1 : k - 1] >> 32))) {
434 vec.emplace_back(arr[i]);
439 void min_syncmer(std::vector<std::pair<uint32_t, uint64_t>> &vec) {
441 unsigned int j = k - 1;
442 for (
int l = k - 2; l >= 0; l--) {
443 if (arr[l] > arr[j]) {
448 std::max(uint32_t(arr[i] >> 32),
449 uint32_t(arr[i ? i - 1 : k - 1] >> 32))) {
450 vec.emplace_back(arr[i], ~(uint64_t)(arr[j] >> 32));
453 if (arr[last] >> 32 ==
454 std::max(uint32_t(arr[i] >> 32),
455 uint32_t(arr[i ? i - 1 : k - 1] >> 32))) {
456 vec.emplace_back(arr[i], ~(uint64_t)(arr[last] >> 32));