QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#322872#6549. Two Missing Numbershotboy27030 67ms4716kbC++143.7kb2024-02-07 21:41:282024-02-07 21:41:28

Judging History

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

  • [2024-02-07 21:41:28]
  • 评测
  • 测评结果:0
  • 用时:67ms
  • 内存:4716kb
  • [2024-02-07 21:41:28]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define pll pair <ll,ll>
#define fi first
#define se second
#define sz(a) (ll((a).size()))
#define MASK(i) (1LL<<(i))
#define BIT(mask,i) (((mask) >> (i))&1LL)
namespace nimber{
    //inspired by adamant && https://natsugiri.hatenablog.com/entry/2020/03/29/073605
    bool log_computed = 0;
    const ull small = MASK(16);
    ull pw[small],lg[small];
    ull mul(ull a,ull b,ull half = 32){
        if (a <= 1 || b <= 1)return a*b;
        if (log_computed && a < small && b < small){
            ull t = lg[a] + lg[b];
            if (t >= small-1){
                t-=small-1;
            }
            return pw[t];
        }
        ull mask = MASK(half)-1;
        //P = MASK(half);
        ull a0 = a & mask,a1 = a >> half;
        ull b0 = b & mask,b1 = b >> half;
        //a * b = (a1 * P + a0) * (b1 * P + b0) = a0 * b0 + P * (a1 * b0 + a0 * b1) + P * P * (a1 * b1)
        ull A = mul(a0,b0,half/2);
        ull C = mul(a1,b1,half/2);
        ull B = mul(a0^a1,b0^b1,half/2) ^ A ^ C; // a1*b0+a0*b1 = (a0+a1) * (b0+b1) - A - C
        B = (B<<half);
        C = (C<<half) ^ mul(C,MASK(half-1),half/2);
        return A^B^C;
    }
    bool init(){
        const ull base = 696;//some base does not work(cycle issue) but 696 does work heeheeheehaw
        pw[0] = 1;
        lg[1] = 0;
        for (ull i = 1;i < small-1;i ++){
            pw[i] = mul(pw[i-1],base);
            lg[pw[i]] = i;
        }
        log_computed = 1;
        return 1;
    }
    bool pre_computed = init();
    struct nim{
        ull v;
        nim(ull x=0):v(x){}
        nim operator * (nim u){return mul(v,u.v);}
        nim operator + (nim u){return v^u.v;}
        nim pw(ull y){
            nim res = 1;
            for (nim x = *this;y;y>>=1,x=x*x){
                if (y&1)res = res*x;
            }
            return res;
        }
        nim inv(){return pw(-2ULL);}
        nim sqrt(){return pw(MASK(63));}

    };
    //find nimber x satisfies: x*x + x + c = 0;
    ull little_quadratic(ull c,ll half = 4){
        //x*x+x=c
        if (half == 0){
            return 0;
        }
        //x1 * P + x0 = x
        //(x1^2+x1) * P + (x0 ^ 2 + x0 + P/2 * x1 * x1) = c1 * P + c0
        ull mask = MASK(half) - 1;
        ull c0 = c & mask,c1 = c >> half;
        ull x1 = little_quadratic(c1,half/2);
        if ((mul(mul(x1,x1,half/2),MASK(half-1),half/2) ^ c0) >= ull(MASK(half-1)))x1 ^= 1;
        ull x0 = little_quadratic(mul(mul(x1,x1,half/2),MASK(half-1),half/2) ^ c0,half/2);
        ull res = (x1<<half)^x0;
//        cout<<c<<' '<<half <<' '<<x0<<' '<<x1<<' '<<res<<'\n';
        return res;
    }
    nim little_quadratic(nim c){
        return little_quadratic(c.v);
    }
    //find nimber z satisfies: z*z + bz + d = 0;
    nim full_quadratic(nim b,nim d){
        if (b.v==0)return d.sqrt();
        else{
            //z = bx, b^2*x^2+b^2*x+d=0 <=> x^2 + x + c = 0 (c = d/b^2)
//            cout<<d.v<<' '<<b.v<<' '<<(b*b).inv().v<<' '<<(d*((b*b).inv())).v<<'\n';
            return little_quadratic(d*((b*b).inv()))*b;
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
    using namespace nimber;
    ll q,n;
    cin>>q>>n;
    nim a1,a3;
    if (q==2)cin>>a1.v>>a3.v;
    for (ll i = 1;i <= n;i ++){
        nim x;
        cin>>x.v;
        a1 = a1+x;
        a3 = a3+x*x*x;
//        cout<<(x*x*x).v<<'\n';
    }
    if (q==1){
        cout<<a1.v<<' '<<a3.v<<'\n';
    }
    else{
        nim ab = a3*a1.inv()+a1*a1;
        nim a = full_quadratic(a1,ab);
        nim b = a1 + a;
        cout<<a.v<<' '<<b.v<<'\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 63ms
memory: 4696kb

First Run Input

1 5
5 1 4 4 5

First Run Output

1 1

Second Run Input

2 3 1 1
9 9 3 

Second Run Output

3 1

result:

ok correct

Test #2:

score: 100
Accepted
time: 67ms
memory: 4692kb

First Run Input

1 1
0

First Run Output

0 0

Second Run Input

2 1 0 0
1

Second Run Output

0 1

result:

ok correct

Test #3:

score: 0
Wrong Answer
time: 67ms
memory: 4716kb

First Run Input

1 1
10625130587464985929

First Run Output

10625130587464985929 1640162740173739743

Second Run Input

2 1 10625130587464985929 1640162740173739743
1167154569617655189

Second Run Output

3563327085256105960 12841416232829974324

result:

wrong answer incorrect, read 3563327085256105960 12841416232829974324 but expected 1167154569617655189 10625130587464985929