QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108888#4471. 随机立方体myee100 ✓1897ms118608kbC++114.9kb2023-05-26 21:09:072023-05-26 21:09:08

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-26 21:09:08]
  • 评测
  • 测评结果:100
  • 用时:1897ms
  • 内存:118608kb
  • [2023-05-26 21:09:07]
  • 提交

answer

// 搁这儿搬 CTS2019 的题还是太毒瘤了些吧(虽然上课讲过了)。
// 思路:高维二项式反演 + 定序讨论。
// 过于牛逼。

#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
namespace ConstMod
{
    template<const ullt p>
    class mod_ullt
    {
        private:
            ullt v;
            inline ullt chg(ullt w){return(w<p)?w:w-p;}
            inline mod_ullt _chg(ullt w){mod_ullt ans;ans.v=(w<p)?w:w-p;return ans;}
        public:
            mod_ullt():v(0){}
            mod_ullt(ullt v):v(v%p){}
            bol empty(){return!v;}
            inline ullt val(){return v;}
            friend bol operator<(mod_ullt a,mod_ullt b){return a.v<b.v;}
            friend bol operator>(mod_ullt a,mod_ullt b){return a.v>b.v;}
            friend bol operator<=(mod_ullt a,mod_ullt b){return a.v<=b.v;}
            friend bol operator>=(mod_ullt a,mod_ullt b){return a.v>=b.v;}
            friend bol operator==(mod_ullt a,mod_ullt b){return a.v==b.v;}
            friend bol operator!=(mod_ullt a,mod_ullt b){return a.v!=b.v;}
            inline friend mod_ullt operator+(mod_ullt a,mod_ullt b){return a._chg(a.v+b.v);}
            inline friend mod_ullt operator-(mod_ullt a,mod_ullt b){return a._chg(a.v+a.chg(p-b.v));}
            inline friend mod_ullt operator*(mod_ullt a,mod_ullt b){return a.v*b.v;}
            friend mod_ullt operator/(mod_ullt a,mod_ullt b){return b._power(p-2)*a.v;}
            friend mod_ullt operator^(mod_ullt a,ullt b){return a._power(b);}
            inline mod_ullt operator-(){return _chg(p-v);}
            mod_ullt sqrt()
            {
                if(power(v,(p-1)>>1,p)!=1)return 0;
                mod_ullt b=1;do b++;while(b._power((p-1)>>1)==1);
                ullt t=p-1,s=0,k=1;while(!(t&1))s++,t>>=1;
                mod_ullt x=_power((t+1)>>1),e=_power(t);
                while(k<s)
                {
                    if(e._power(1llu<<(s-k-1))!=1)x*=b._power((1llu<<(k-1))*t);
                    e=_power(p-2)*x*x,k++;
                }
                return _min(x,-x),x;
            }
            mod_ullt inv(){return _power(p-2);}
            mod_ullt _power(ullt index){mod_ullt ans(1),w(v);while(index){if(index&1)ans*=w;w*=w,index>>=1;}return ans;}
            voi read(){v=0;chr c;do c=getchar();while(c>'9'||c<'0');do v=(c-'0'+v*10)%p,c=getchar();while(c>='0'&&c<='9');v%=p;}
            voi print()
            {
                static chr C[20];uint tp=0;
                ullt w=v;do C[tp++]=w%10+'0',w/=10;while(w);
                while(tp--)putchar(C[tp]);
            }
            voi println(){print(),putchar('\n');}
            mod_ullt operator++(int){mod_ullt ans=*this;return v=chg(v+1),ans;}
        public:
            inline ullt&operator()(){return v;}
            inline mod_ullt&operator+=(mod_ullt b){return*this=_chg(v+b.v);}
            inline mod_ullt&operator-=(mod_ullt b){return*this=_chg(v+chg(p-b.v));}
            inline mod_ullt&operator*=(mod_ullt b){return*this=v*b.v;}
            mod_ullt&operator^=(ullt b){return*this=_power(b);}
            mod_ullt&operator/=(mod_ullt b){return*this=b._power(p-2)*v;}
            mod_ullt&operator++(){return v=chg(v+1),*this;}
    };
}
const ullt Mod=998244353;
typedef ConstMod::mod_ullt<Mod>modint;
typedef std::vector<modint>modvec;
modint X[5000005],Y[5000005];
modint V[5000005];
int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    freopen("QAQ.out","w",stdout);
#endif
    X[0]=1;for(uint i=1;i<=5000000;i++)X[i]=X[i-1]*i;
    Y[5000000]=X[5000000].inv();for(uint i=5000000;i;i--)Y[i-1]=Y[i]*i;
    uint t;scanf("%u",&t);
    while(t--)
    {
        uint n,m,l,k;scanf("%u%u%u%u",&n,&m,&l,&k);
        uint Lim=std::min({n,m,l});
        V[Lim]=1;for(uint i=Lim;i;i--)V[i-1]=V[i]*(modint(n)*m*l-(modint(n)-i)*(m-i)*(l-i));
        V[0]=V[0].inv();for(uint i=1;i<=Lim;i++)V[i]*=V[0];
        modint ans;
        for(uint i=k;i<=Lim;i++)
            ans+=((i-k)&1?Mod-1:1)
                *X[n]*Y[n-i]
                *X[m]*Y[m-i]
                *X[l]*Y[l-i]
                *X[i]*Y[i-k]*Y[k]
                *V[i];
        ans.println();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 41ms
memory: 118488kb

input:

9
1 2 2 1
2 1 2 1
2 2 2 1
2 2 1 1
1 2 3 1
2 2 3 1
1 1 3 1
1 2 1 1
2 2 3 1

output:

1
1
142606337
1
1
399297742
1
1
399297742

result:

ok 9 numbers

Test #2:

score: 10
Accepted
time: 52ms
memory: 118496kb

input:

10
11 12 11 1
12 12 10 1
10 12 12 1
12 8 4 1
12 7 10 1
10 12 12 1
12 11 12 1
12 12 10 1
12 8 5 1
11 12 10 1

output:

964117340
313668413
313668413
391814806
769515445
313668413
409827311
313668413
276258321
547984948

result:

ok 10 numbers

Test #3:

score: 10
Accepted
time: 41ms
memory: 118496kb

input:

10
12 11 11 11
12 12 2 2
12 11 8 5
12 10 10 9
9 12 9 4
11 12 12 6
12 4 12 5
11 12 10 3
10 11 11 3
11 12 12 8

output:

668009782
890649154
271209916
937875427
630982635
140920141
0
437327840
742478817
773295187

result:

ok 10 numbers

Test #4:

score: 10
Accepted
time: 50ms
memory: 118572kb

input:

10
100 66 92 57
97 100 77 3
100 92 95 69
86 98 97 30
91 94 98 85
35 95 54 96
91 20 93 2
71 100 81 65
93 96 100 3
100 100 68 20

output:

314376207
763625649
23307893
827148291
280829208
0
122744808
628776470
314819928
823785335

result:

ok 10 numbers

Test #5:

score: 10
Accepted
time: 63ms
memory: 118516kb

input:

10
992 924 949 1
991 507 917 1
992 595 701 1
937 992 967 1
983 960 905 1
992 932 996 1
995 971 645 1
917 992 996 1
994 993 996 1
15 1000 1000 1

output:

229417522
351302489
629390104
246106927
862307736
844052618
66055569
913422543
337236312
278988015

result:

ok 10 numbers

Test #6:

score: 10
Accepted
time: 74ms
memory: 118604kb

input:

10
94710 91605 99101 55
18512 79378 99834 1
99658 97773 92656 31
99155 99139 99698 44
99747 94914 99742 49
97452 99398 96607 87
86012 76191 75937 42
99217 98167 99164 32
98058 87372 57032 73
92807 73444 99668 15

output:

11312811
294655439
70723955
151174517
538799105
344255344
899533255
429432051
2152996
431450316

result:

ok 10 numbers

Test #7:

score: 10
Accepted
time: 316ms
memory: 118496kb

input:

10
520078 928588 676646 1
992873 719234 702486 1
996614 861181 152528 1
996654 927109 996108 1
830126 218745 922743 1
587118 796679 905415 1
922146 969275 731212 1
970141 851397 997226 1
923346 780416 990579 1
944434 929901 992364 1

output:

638628415
78605624
973978919
300798323
441618627
565785141
918707550
591320093
313210070
0

result:

ok 10 numbers

Test #8:

score: 10
Accepted
time: 323ms
memory: 118608kb

input:

10
995437 970803 346183 19
991927 994256 906723 21
992315 648327 901145 70
924884 978458 948349 48
955785 951761 326193 50
860923 165778 939919 53
991512 983509 983023 55
990758 995005 714970 14
996251 621454 992477 78
990147 880093 908839 70

output:

168170437
674625485
575021422
657991968
539858782
978379982
512209101
317609800
271534305
442516894

result:

ok 10 numbers

Test #9:

score: 10
Accepted
time: 1676ms
memory: 118544kb

input:

10
4812995 4597958 4997619 1
4698223 4927285 4716397 1
3888126 4497028 4513559 1
4953155 4982658 4622527 1
3990178 4958258 2671458 1
357883 4956337 3719989 1
4923080 4997234 4841397 1
4980872 4973577 4695751 1
4670227 4530539 4986963 1
4851624 4632350 4558600 1

output:

723910072
849159504
341235107
503935908
616030546
686260469
205958291
476672538
598436093
346856672

result:

ok 10 numbers

Test #10:

score: 10
Accepted
time: 1897ms
memory: 118512kb

input:

10
4973645 4986915 4849600 96
4951053 4740469 3999936 56
4719113 4869923 4985155 72
4973301 4708629 4982742 92
4743191 4885631 4953269 85
4530720 4959089 4976548 17
4975615 4910052 4988683 69
4980376 4971246 3830334 75
4699883 4988989 4191443 82
4553734 4965926 4962568 75

output:

239923778
769296696
92076376
412346289
771403526
683282238
697454766
396743794
967155247
990632942

result:

ok 10 numbers

Extra Test:

score: 0
Extra Test Passed