QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#456261 | #6549. Two Missing Numbers | pandapythoner | Compile Error | / | / | C++23 | 5.6kb | 2024-06-27 16:35:46 | 2024-06-27 16:35:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ulll __uint128_t
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for(int i = 0; i < n; i += 1)
const ll inf = 1e18;
mt19937 rnd(234);
ostream& operator<<(ostream& out, ulll x) {
out << (ull)x;
return out;
}
istream& operator>>(istream& in, ulll& x) {
ull a;
in >> a;
x = a;
return in;
}
ulll mul(ulll a, ulll b) {
if (a == 0 or b == 0) {
return 0;
}
ulll c = 0;
int k = __lg(a);
rep(i, k + 1) if ((a >> i) & 1) c ^= (b << i);
return c;
}
ulll mod(ulll a, ulll m) {
assert(m != 0);
if (m == 1) {
return 0;
}
if (a == 0) {
return 0;
}
int k = __lg(m);
int d = __lg(a);
if (d < k) {
return a;
}
vector<ulll> f(d + 1);
ulll c = 0;
rep(i, k) {
f[i] = (((ulll)1) << i);
if ((a >> i) & 1) {
c ^= f[i];
}
}
for (int i = k; i <= d; i += 1) {
f[i] = 0;
for (int j = 0; j < k; j += 1) {
if ((m >> j) & 1) {
f[i] ^= f[i - k + j];
}
}
if ((a >> i) & 1) {
c ^= f[i];
}
}
return c;
}
pair<ulll, ulll> mod_div(ulll a, ulll m) {
assert(m != 0);
if (m == 1) {
return { 0, a };
}
if (a == 0) {
return { 0, 0 };
}
int k = __lg(m);
int d = __lg(a);
if (d < k) {
return { a, 0 };
}
vector<pair<ulll, ulll>> f(d + 1);
ulll c = 0;
ulll e = 0;
rep(i, k) {
f[i] = make_pair((((ulll)1) << i), 0);
if ((a >> i) & 1) {
c ^= f[i].first;
e ^= f[i].second;
}
}
for (int i = k; i <= d; i += 1) {
f[i] = make_pair(0, (((ulll)1) << (i - k)));
for (int j = 0; j < k; j += 1) {
if ((m >> j) & 1) {
f[i].first ^= f[i - k + j].first;
f[i].second ^= f[i - k + j].second;
}
}
if ((a >> i) & 1) {
c ^= f[i].first;
e ^= f[i].second;
}
}
return { c, e };
}
ulll mul_mod(ulll a, ulll b, ulll m) {
return mod(mul(a, b), m);
}
ulll gcd(ulll a, ulll b) {
while (a != 0) {
b = mod(b, a);
swap(a, b);
}
return b;
}
array<ulll, 3> gcdex(ulll a, ulll b) {
if (a == 0) {
return { b, 0, 1 };
}
auto [c, d] = mod_div(b, a);
auto [g, x, y] = gcdex(c, a);
return { g, y ^ mul(d, x), x };
}
ulll multiple_square(ulll a, ll cnt, ulll m) {
ulll c = a;
rep(i, cnt) c = mul_mod(c, c, m);
return c;
}
ulll check_irreducible(ulll a) {
assert(a != 0);
int k = __lg(a);
assert(k >= 1 and k <= 64);
for (int i = 1; i <= k / 2; i += 1) {
ulll f = multiple_square(2, i, a) ^ 2;
ulll g = gcd(a, f);
if (g != 1) {
return false;
}
}
return true;
}
ulll find_irreducible(int k) {
assert(k >= 1);
auto gen = [&]() {
ulll c = (((ulll)1) << k);
rep(i, k) if (rnd() % 2) c += (((ulll)1) << i);
return c;
};
while (1) {
ulll x = gen();
if (check_irreducible(x)) {
return x;
}
}
}
const int base = 64;
const ulll m = find_irreducible(base);
ulll inv(ulll a) {
assert(a != 0);
auto [g, x, y] = gcdex(a, m);
assert(g == 1);
return x;
}
pair<ulll, ulll> find_roots(ulll a, ulll b) {
// finds roots of x^2 + a*x + b = 0
// assumes, that there is exactly two different nonzero roots
ulll power = ((((ulll)1) << base) - 1) / 3;
auto mul_poly = [&](ulll p0, ulll p1, ulll q0, ulll q1) -> pair<ulll, ulll> {
ulll t0 = mul_mod(p0, q0, m);
ulll t1 = mul_mod(p1, q0, m) ^ mul_mod(p0, q1, m);
ulll c = mul_mod(p1, q1, m);
t1 ^= mul_mod(c, a, m);
t0 ^= mul_mod(c, b, m);
return { t0, t1 };
};
function<pair<ulll, ulll>(ulll, ulll, ulll)> bin_pow_poly;
bin_pow_poly = [&](ulll p, ulll q, ulll n) -> pair<ulll, ulll> {
if (n == 0) {
return { 1, 0 };
}
auto [f0, f1] = bin_pow_poly(p, q, n / 2);
auto [a0, a1] = mul_poly(f0, f1, f0, f1);
if (n & 1) {
return mul_poly(a0, a1, p, q);
}
return { a0, a1 };
};
while (1) {
ulll r = mul_mod(rnd(), rnd(), m);
auto [a0, a1] = bin_pow_poly(r, 1, power);
a0 ^= 1;
if (a1 != 0) {
ulll first_root = mul_mod(a0, inv(a1), m);
ulll second_root = a ^ first_root;
if (mul_mod(first_root, second_root, m) == b) {
return { first_root, second_root };
}
}
}
}
ulll cube(ulll a) {
return mul_mod(mul_mod(a, a, m), a, m);
}
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int q, n;
cin >> q >> n;
ulll a = 0, b = 0;
if (q == 2) {
cin >> a >> b;
}
rep(i, n) {
ulll x;
cin >> x;
a ^= x;
b ^= cube(x);
}
if (q == 2) {
ulll sum = a;
ulll prod = mul_mod(cube(a) ^ b, inv(a), m);
auto [x, y] = find_roots(sum, prod);
cout << x << " " << y << "\n";
} else {
cout << a << " " << b << "\n";
}
return 0;
}
Details
answer.code: In function ‘__int128 unsigned mul(__int128 unsigned, __int128 unsigned)’: answer.code:37:17: error: call of overloaded ‘__lg(__int128 unsigned&)’ is ambiguous 37 | int k = __lg(a); | ~~~~^~~ In file included from /usr/include/c++/11/bits/specfun.h:45, from /usr/include/c++/11/cmath:1935, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41, from answer.code:1: /usr/include/c++/11/bits/stl_algobase.h:1506:3: note: candidate: ‘constexpr int std::__lg(int)’ 1506 | __lg(int __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1510:3: note: candidate: ‘constexpr unsigned int std::__lg(unsigned int)’ 1510 | __lg(unsigned __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1514:3: note: candidate: ‘constexpr long int std::__lg(long int)’ 1514 | __lg(long __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1518:3: note: candidate: ‘constexpr long unsigned int std::__lg(long unsigned int)’ 1518 | __lg(unsigned long __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1522:3: note: candidate: ‘constexpr long long int std::__lg(long long int)’ 1522 | __lg(long long __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1526:3: note: candidate: ‘constexpr long long unsigned int std::__lg(long long unsigned int)’ 1526 | __lg(unsigned long long __n) | ^~~~ answer.code: In function ‘__int128 unsigned mod(__int128 unsigned, __int128 unsigned)’: answer.code:51:17: error: call of overloaded ‘__lg(__int128 unsigned&)’ is ambiguous 51 | int k = __lg(m); | ~~~~^~~ In file included from /usr/include/c++/11/bits/specfun.h:45, from /usr/include/c++/11/cmath:1935, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41, from answer.code:1: /usr/include/c++/11/bits/stl_algobase.h:1506:3: note: candidate: ‘constexpr int std::__lg(int)’ 1506 | __lg(int __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1510:3: note: candidate: ‘constexpr unsigned int std::__lg(unsigned int)’ 1510 | __lg(unsigned __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1514:3: note: candidate: ‘constexpr long int std::__lg(long int)’ 1514 | __lg(long __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1518:3: note: candidate: ‘constexpr long unsigned int std::__lg(long unsigned int)’ 1518 | __lg(unsigned long __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1522:3: note: candidate: ‘constexpr long long int std::__lg(long long int)’ 1522 | __lg(long long __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1526:3: note: candidate: ‘constexpr long long unsigned int std::__lg(long long unsigned int)’ 1526 | __lg(unsigned long long __n) | ^~~~ answer.code:52:17: error: call of overloaded ‘__lg(__int128 unsigned&)’ is ambiguous 52 | int d = __lg(a); | ~~~~^~~ In file included from /usr/include/c++/11/bits/specfun.h:45, from /usr/include/c++/11/cmath:1935, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41, from answer.code:1: /usr/include/c++/11/bits/stl_algobase.h:1506:3: note: candidate: ‘constexpr int std::__lg(int)’ 1506 | __lg(int __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1510:3: note: candidate: ‘constexpr unsigned int std::__lg(unsigned int)’ 1510 | __lg(unsigned __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1514:3: note: candidate: ‘constexpr long int std::__lg(long int)’ 1514 | __lg(long __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1518:3: note: candidate: ‘constexpr long unsigned int std::__lg(long unsigned int)’ 1518 | __lg(unsigned long __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1522:3: note: candidate: ‘constexpr long long int std::__lg(long long int)’ 1522 | __lg(long long __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1526:3: note: candidate: ‘constexpr long long unsigned int std::__lg(long long unsigned int)’ 1526 | __lg(unsigned long long __n) | ^~~~ answer.code: In function ‘std::pair<__int128 unsigned, __int128 unsigned> mod_div(__int128 unsigned, __int128 unsigned)’: answer.code:87:17: error: call of overloaded ‘__lg(__int128 unsigned&)’ is ambiguous 87 | int k = __lg(m); | ~~~~^~~ In file included from /usr/include/c++/11/bits/specfun.h:45, from /usr/include/c++/11/cmath:1935, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41, from answer.code:1: /usr/include/c++/11/bits/stl_algobase.h:1506:3: note: candidate: ‘constexpr int std::__lg(int)’ 1506 | __lg(int __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:1510:3: note: candidate: ‘constexpr unsigned int std::__lg(unsigned int)’ 1510 | __lg(unsigned __n) | ^~~~ /usr/include/c++/11/bits/stl_algobase.h:15...