Skip to content

Commit 447c340

Browse files
authored
Merge pull request #420 from hitonanode/fix-on-binary-trie
abc451 binary trie fix
2 parents f3ce7b2 + 72f34f1 commit 447c340

5 files changed

Lines changed: 10 additions & 6 deletions

File tree

data_structure/binary_trie.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ template <class Int, class Count = int> struct BinaryTrie {
8585

8686
// Count elements y such that x ^ y < thres
8787
Count count_less_xor(Int x, Int thres) const {
88+
if (thres <= 0) return Count();
89+
if ((thres >> maxD) > 0) return subtree_sum[0];
8890
Count ret = Count();
8991
int now = 0;
9092

data_structure/binary_trie.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ Key v = bt.xor_min(t); // t ^ x (x は現在存在する値)の最小値を
2626
2727
- [Library Checker: Set Xor-Min](https://judge.yosupo.jp/problem/set_xor_min)
2828
- [No.2977 Kth Xor Pair - yukicoder](https://yukicoder.me/problems/no/2977)
29+
- [AtCoder Beginner Contest 451 G - Minimum XOR Walk](https://atcoder.jp/contests/abc451/tasks/abc451_g)

number/primitive_root.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
// - 163577857 ( = (39 << 22) + 1 ) -> 23
1717
// - 2 -> 1
1818
// - 1 -> -1
19-
long long find_smallest_primitive_root(long long n) {
19+
inline long long find_smallest_primitive_root(long long n) {
2020
std::vector<long long> fac;
2121
const long long phi = FactorizeLonglong.euler_phi(n);
2222
for (long long q : FactorizeLonglong(phi)) {
2323
if (fac.empty() or fac.back() != q) fac.push_back(q);
2424
}
2525

2626
for (long long g = 1; g < n; g++) {
27-
if (std::__gcd(n, g) != 1) continue;
27+
if (std::gcd(n, g) != 1) continue;
2828
if (pow_mod<long long, __int128>(g, phi, n) != 1) return -1;
2929
bool ok = true;
3030
for (auto pp : fac) {

number/test/binary_gcd.stress.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A" // DUMMY
22
#include "../binary_gcd.hpp"
3-
#include <algorithm> // __gcd
43
#include <iostream>
4+
#include <numeric>
55
using namespace std;
66

77
template <typename Int> void test_binary_gcd(Int lo, Int hi) {
88
for (Int x = lo; x <= hi; x++) {
99
for (Int y = lo; y <= hi; y++) {
10-
auto g = __gcd<Int>(x, y);
10+
auto g = gcd<Int>(x, y);
1111
if (g < 0) g = -g;
1212
if (binary_gcd(x, y) != g) {
1313
cerr << "Did not match : (x, y) = " << x << ',' << y << ')' << endl;

number/test/zeta_moebius_transform.test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../../modint.hpp"
44
#include <cassert>
55
#include <iostream>
6+
#include <numeric>
67
#include <vector>
78
using namespace std;
89

@@ -77,7 +78,7 @@ void test_gcdconv() {
7778
vector<mint> x = vecgen(n), y = vecgen(n), z(n + 1);
7879
auto conv = gcdconv(x, y);
7980
for (int i = 1; i <= n; ++i) {
80-
for (int j = 1; j <= n; ++j) z[__gcd(i, j)] += x[i] * y[j];
81+
for (int j = 1; j <= n; ++j) z[gcd(i, j)] += x[i] * y[j];
8182
}
8283
assert(conv == z);
8384
}
@@ -91,7 +92,7 @@ void test_lcmconv() {
9192
auto conv = lcmconv(x, y);
9293
for (int i = 1; i <= n; ++i) {
9394
for (int j = 1; j <= n; ++j) {
94-
int l = i * j / __gcd(i, j);
95+
int l = i * j / gcd(i, j);
9596
if (l <= n) z[l] += x[i] * y[j];
9697
}
9798
}

0 commit comments

Comments
 (0)