QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214686#6549. Two Missing Numbersucup-team1469#0 6ms4604kbC++176.2kb2023-10-14 22:59:192023-10-14 22:59:19

Judging History

你现在查看的是最新测评结果

  • [2023-10-14 22:59:19]
  • 评测
  • 测评结果:0
  • 用时:6ms
  • 内存:4604kb
  • [2023-10-14 22:59:19]
  • 提交

answer

#ifndef LOCAL
#define FAST_IO
#endif

// ============
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define OVERRIDE(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, m, n) for (i32 i = (i32)(m); i < (i32)(n); ++i)
#define REP(...) OVERRIDE(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER(i, n) for (i32 i = (i32)(n) - 1; i >= 0; --i)
#define ALL(x) begin(x), end(x)

using namespace std;

using u32 = unsigned int;
using u64 = unsigned long long;
using i32 = signed int;
using i64 = signed long long;
using f64 = double;
using f80 = long double;

template <typename T>
using Vec = vector<T>;

template <typename T>
bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

#ifdef INT128

using u128 = __uint128_t;
using i128 = __int128_t;

istream &operator>>(istream &is, i128 &x) {
    i64 v;
    is >> v;
    x = v;
    return is;
}
ostream &operator<<(ostream &os, i128 x) {
    os << (i64)x;
    return os;
}
istream &operator>>(istream &is, u128 &x) {
    u64 v;
    is >> v;
    x = v;
    return is;
}
ostream &operator<<(ostream &os, u128 x) {
    os << (u64)x;
    return os;
}

#endif

[[maybe_unused]] constexpr i32 INF = 1000000100;
[[maybe_unused]] constexpr i64 INF64 = 3000000000000000100;
struct SetUpIO {
    SetUpIO() {
#ifdef FAST_IO
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
#endif
        cout << fixed << setprecision(15);
    }
} set_up_io;
// ============

#ifdef DEBUGF
#else
#define DBG(x) (void)0
#endif

// https://judge.yosupo.jp/submission/110208
namespace nim{
	const uint M=(1<<16)-1,S=2*M+7;
	uint ln[M+1],e[S*2+7];
	template<int k>uint slow(uint a,uint b){
		if constexpr(k==0)return a&b;
		else{
			uint s=1u<<(k-1),m=(1u<<s)-1;
			uint x=a>>s,p=a&m,y=b>>s,q=b&m,z=slow<k-1>(p,q);
			return (slow<k-1>(x^p,y^q)^z)<<s^slow<k-1>(slow<k-1>(x,y),1u<<(s-1))^z;
		}
	}
	void init(){
		const uint w=10279;
		uint cur=1;
		REP(i,M){
			e[i]=cur;
			ln[e[i]]=i;
			cur=slow<4>(cur,w);
		}
		REP(i,M,S)e[i]=e[i-M];
		ln[0]=S;
	}
	uint m16(uint a,uint b){return e[ln[a]+ln[b]];}
	uint m16x15(uint a,uint b){return e[ln[a]+ln[b]+3];}
	uint x31(uint a){
		uint x=a>>16,p=a&M;
		return e[ln[x^p]+3]<<16^e[ln[x]+6];
	}
	uint mult(uint a,uint b){
		uint x=a>>16,p=a&M,y=b>>16,q=b&M,z=m16(p,q);
		return (m16(x^p,y^q)^z)<<16^m16x15(x,y)^z;
	}
	u64 mult(u64 a,u64 b){
		uint x=a>>32,p=a,y=b>>32,q=b,z=mult(p,q);
		return u64(mult(x^p,y^q)^z)<<32^x31(mult(x,y))^z;
	}
}

u32 nim_sqrt_16(u32 x) {
    static Vec<u32> ans;
    static bool first = true;
    if (first) {
        ans.resize(1 << 16);
        REP(i, 1 << 16) {
            ans[nim::mult(u32(i), u32(i))] = i;
        }
        first = false;
    }
    return ans[x];
}
u32 nim_sqrt_32(u32 x) {
    u32 u = x >> 16, d = x ^ (u << 16);
    u32 su = nim_sqrt_16(u);
    u32 sd = nim_sqrt_16(d ^ nim::mult(nim::mult(su, su), 1u << 15));
    return (su << 16) ^ sd;
}
u64 nim_sqrt_64(u64 x) {
    u32 u = x >> 32, d = u32(x);
    u32 su = nim_sqrt_32(u);
    u32 sd = nim_sqrt_32(d ^ nim::mult(nim::mult(su, su), 1u << 31));
    return (u64(su) << 32) ^ sd;
}

u32 nim_inv_8(u32 x) {
    static Vec<u32> ans;
    static bool first = true;
    if (first) {
        ans.resize(1 << 8);
        REP(i, 1 << 8) REP(j, 1 << 8) if (nim::mult(u32(i), u32(j)) == 1) {
            ans[i] = j;
        }
        first = false;
    }
    return ans[x];
}
u32 nim_inv_16(u32 x) {
    u32 u = x >> 8, d = x ^ (u << 8);
    u32 small = nim::mult(d, d) ^ nim::mult(d, u) ^ nim::mult(nim::mult(u, u), 1u << 7);
    u32 bu = nim::mult(u, nim_inv_8(small));
    if (u) {
        u32 bd = nim::mult(nim_inv_8(u), nim::mult((u ^ d), bu));
        return (bu << 8) ^ bd;
    } else {
        u32 bd = nim::mult(nim_inv_8(d), nim::mult(nim::mult(u, bu), 1u << 7) ^ 1);
        return (bu << 8) ^ bd;
    }
}
u32 nim_inv_32(u32 x) {
    u32 u = x >> 16, d = x ^ (u << 16);
    u32 small = nim::mult(d, d) ^ nim::mult(d, u) ^ nim::mult(nim::mult(u, u), 1u << 15);
    u32 bu = nim::mult(u, nim_inv_16(small));
    if (u) {
        u32 bd = nim::mult(nim_inv_16(u), nim::mult((u ^ d), bu));
        return (bu << 16) ^ bd;
    } else {
        u32 bd = nim::mult(nim_inv_16(d), nim::mult(nim::mult(u, bu), 1u << 15) ^ 1);
        return (bu << 16) ^ bd;
    }
}
u64 nim_inv_64(u64 x) {
    u32 u = x >> 32, d = u32(x);
    u32 small = nim::mult(d, d) ^ nim::mult(d, u) ^ nim::mult(nim::mult(u, u), 1u << 31);
    u32 bu = nim::mult(u, nim_inv_32(small));
    if (u) {
        u32 bd = nim::mult(nim_inv_32(u), nim::mult((u ^ d), bu));
        return (u64(bu) << 32) ^ bd;
    } else {
        u32 bd = nim::mult(nim_inv_32(d), nim::mult(nim::mult(u, bu), 1u << 31) ^ 1);
        return (u64(bu) << 32) ^ bd;
    }
}

// x + y = a, x / y = b (in Nimber)
pair<u64, u64> solve(u64 a, u64 b) {
    u64 x = nim::mult(nim::mult(a, b), nim_inv_64(b ^ 1));
    u64 y = a ^ x;
    return make_pair(x, y);
}

constexpr u64 CONST = 0xffeeddcc01234567;

int main() {
    nim::init();
    i32 q;
    i32 n;
    u64 x = 0, y = 0;
    cin >> q >> n;
    if (q == 2) {
        cin >> x >> y;
    }
    Vec<u64> a(n);
    REP(i, n) {
        cin >> a[i];
    }
    sort(ALL(a));
    Vec<u64> b;
    REP(i, n) {
        if ((i != 0 && a[i - 1] == a[i]) || (i != n - 1 && a[i + 1] == a[i])) {
            continue;
        }
        b.push_back(a[i]);
    }
    a = b;
    n = (i32)a.size();
    REP(i, n) {
        a[i] += CONST;
    }
    u64 sum = 0, prod = 1;
    for (u64 ele : a) {
        sum ^= ele;
        prod = nim::mult(prod, ele);
    }
    if (q == 1) {
        x = sum;
        y = prod;
        cout << x << ' ' << y << '\n';
    } else {
        x ^= sum;
        y = nim::mult(y, nim_inv_64(prod));
        auto [a, b] = solve(x, y);
        a -= CONST;
        b -= CONST;
        cout << a << ' ' << b << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 4372kb

First Run Input

1 5
5 1 4 4 5

First Run Output

18441921392390915432 18441921392390915432

Second Run Input

2 3 18441921392390915432 18441921392390915432
9 9 3 

Second Run Output

1 3

result:

ok correct

Test #2:

score: 100
Accepted
time: 6ms
memory: 4312kb

First Run Input

1 1
0

First Run Output

18441921392390915431 18441921392390915431

Second Run Input

2 1 18441921392390915431 18441921392390915431
1

Second Run Output

0 1

result:

ok correct

Test #3:

score: 100
Accepted
time: 6ms
memory: 4604kb

First Run Input

1 1
10625130587464985929

First Run Output

10620307906146349744 10620307906146349744

Second Run Input

2 1 10620307906146349744 10620307906146349744
1167154569617655189

Second Run Output

10625130587464985929 1167154569617655189

result:

ok correct

Test #4:

score: 0
Wrong Answer
time: 6ms
memory: 4400kb

First Run Input

1 0

First Run Output

0 1

Second Run Input

2 2 0 1
14205293878974412429 14539925169898881927 

Second Run Output

422197205516168620 684853072852957858

result:

wrong answer incorrect, read 422197205516168620 684853072852957858 but expected 14205293878974412429 14539925169898881927