QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67525 | #2680. 白兔之舞 | alpha1022 | 100 ✓ | 652ms | 22704kb | C++23 | 6.5kb | 2022-12-10 16:58:03 | 2022-12-10 16:58:05 |
Judging History
answer
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define add(a,b) (a + b >= mod ? a + b - mod : a + b)
#define dec(a,b) (a < b ? a - b + mod : a - b)
using namespace std;
const int N = 3;
const int K = 1 << 16;
int n,k,ki,L,x,y,mod,len;
int G,rt[K + 5],ans[K + 5];
inline int fpow(int a,int b)
{
int ret = 1;
for(;b;b >>= 1)
(b & 1) && (ret = (long long)ret * a % mod),a = (long long)a * a % mod;
return ret;
}
struct Matrix
{
int a[N + 5][N + 5];
inline Matrix()
{
memset(a,0,sizeof a);
}
inline Matrix(int)
{
memset(a,0,sizeof a);
for(register int i = 1;i <= n;++i)
a[i][i] = 1;
}
inline int *operator[](const int &x)
{
return a[x];
}
inline const int *operator[](const int &x) const
{
return a[x];
}
inline Matrix operator*(const int &x) const
{
Matrix ret;
for(register int i = 1;i <= n;++i)
for(register int j = 1;j <= n;++j)
ret[i][j] = (long long)a[i][j] * x % mod;
return ret;
}
inline Matrix operator+(const Matrix &o) const
{
Matrix ret;
for(register int i = 1;i <= n;++i)
for(register int j = 1;j <= n;++j)
ret[i][j] = (a[i][j] + o[i][j]) % mod;
return ret;
}
inline Matrix operator*(const Matrix &o) const
{
Matrix ret;
for(register int i = 1;i <= n;++i)
for(register int j = 1;j <= n;++j)
for(register int k = 1;k <= n;++k)
ret[i][j] = (ret[i][j] + (long long)a[i][k] * o[k][j]) % mod;
return ret;
}
} w;
inline Matrix fpow(Matrix a,int b)
{
Matrix ret(1);
for(;b;b >>= 1)
(b & 1) && (ret = ret * a,1),a = a * a;
return ret;
}
namespace Poly
{
const int N = 1 << 18;
const double pi = acos(-1);
const int W = 1 << 15;
int n;
int lg2[N + 5],rev[N + 5];
struct poly
{
int a[N + 5];
inline const int &operator[](int x) const
{
return a[x];
}
inline int &operator[](int x)
{
return a[x];
}
inline void clear(int x = 0)
{
memset(a + x,0,(N - x + 1) << 2);
}
} f,g;
struct cp
{
double a,b;
inline void operator+=(const cp &o)
{
a += o.a,b += o.b;
}
inline cp operator+(const cp &o) const
{
return (cp){a + o.a,b + o.b};
}
inline cp operator-(const cp &o) const
{
return (cp){a - o.a,b - o.b};
}
inline cp operator*(const cp &o) const
{
return (cp){a * o.a - b * o.b,a * o.b + b * o.a};
}
inline void operator*=(const cp &o)
{
*this = *this * o;
}
inline cp operator*(const double &o) const
{
return (cp){a * o,b * o};
}
inline cp operator~() const
{
return (cp){a,-b};
}
} rt[N + 5];
inline void init(int len)
{
for(n = 1;n < len;n <<= 1);
for(register int i = 2;i <= n;++i)
lg2[i] = lg2[i >> 1] + 1;
for(register int i = 0;i <= (n >> 1);++i)
rt[(n >> 1) + i] = (cp){cos(2 * pi * i / n),sin(2 * pi * i / n)};
for(register int i = (n >> 1) - 1;i;--i)
rt[i] = rt[i << 1];
}
inline void fft(cp *a,int type,int n)
{
type == -1 && (reverse(a + 1,a + n),1);
int lg = lg2[n] - 1;
for(register int i = 0;i < n;++i)
rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << lg),
i < rev[i] && (swap(a[i],a[rev[i]]),1);
for(register int w = 2,m = 1;w <= n;w <<= 1,m <<= 1)
for(register int i = 0;i < n;i += w)
for(register int j = 0;j < m;++j)
{
cp t = rt[m | j] * a[i | j | m];
a[i | j | m] = a[i | j] - t,a[i | j] += t;
}
if(type == -1)
for(register int i = 0;i < n;++i)
a[i].a /= n,a[i].b /= n;
}
inline void mul(poly &a,const poly &b,int n)
{
static cp f[N + 5],g[N + 5],h[N + 5];
int lim = 1;
memset(f,0,sizeof f),memset(g,0,sizeof g);
for(;lim < (n << 1);lim <<= 1);
for(register int i = 0;i < n;++i)
f[i] = (cp){a[i] / W,a[i] % W},g[i] = (cp){b[i] / W,b[i] % W};
fft(f,1,lim),fft(g,1,lim);
for(register int i = 0;i < lim;++i)
h[i] = ~f[(lim - i) % lim];
for(register int i = 0;i < lim;++i)
f[i] *= g[i],g[i] *= h[i];
fft(f,-1,lim),fft(g,-1,lim);
for(register int i = 0;i < lim;++i)
{
long long ac = (f[i].a + g[i].a) / 2 + 0.5;
long long bd = g[i].a - ac + 0.5;
long long bcad = f[i].b + 0.5;
a[i] = ((ac % mod * W % mod * W % mod) % mod + (bcad % mod * W % mod) % mod + bd % mod) % mod;
}
}
}
int p[N + 5],t,cnt;
int main()
{
scanf("%d%d%d%d%d%d",&n,&k,&L,&x,&y,&mod);
len = k << 1,Poly::init(len << 1);
t = mod - 1;
for(register int i = 2;i * i <= t;++i)
{
if(!(t % i))
p[++cnt] = i;
for(;!(t % i);t /= i);
}
t > 1 && (p[++cnt] = t);
for(register int i = 2,flag;i < mod;++i)
{
flag = 1;
for(register int j = 1;j <= cnt;++j)
if(fpow(i,(mod - 1) / p[j]) == 1)
{
flag = 0;
break;
}
if(flag)
{
G = i;
break;
}
}
for(register int i = 0;i < k;++i)
rt[i] = fpow(G,(mod - 1) / k * i);
for(register int i = 1;i <= n;++i)
for(register int j = 1;j <= n;++j)
scanf("%d",w.a[i] + j);
for(register int i = 0;i < k;++i)
Poly::f[i] = (long long)fpow(w * rt[i] + Matrix(1),L)[x][y] * rt[(long long)i * (i - 1) / 2 % k] % mod;
for(register int i = 0;i < len - 1;++i)
Poly::g[len - i - 1] = rt[(k - (long long)i * (i - 1) / 2 % k) % k];
Poly::mul(Poly::f,Poly::g,len);
ki = fpow(k,mod - 2);
for(register int i = 0;i < k;++i)
ans[i] = (long long)Poly::f[len - i - 1] * rt[(long long)i * (i - 1) / 2 % k] % mod * ki % mod;
for(register int i = 0;i < k;++i)
printf("%d\n",ans[i]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 516ms
memory: 22600kb
input:
3 60868 28281 3 2 997261313 541377333 663518765 140473546 710072468 931907445 481102683 305037615 409799686 182541807
output:
0 371201393 126497496 594163146 697376876 913426334 898074565 482372234 553603826 843803081 795054178 946616702 269569577 553650707 14378087 357646765 564252630 697568136 993140951 343394961 414668895 417765343 92116860 146582844 341872589 91292219 712827656 498229323 241600152 737288617 254539718 9...
result:
ok 60868 lines
Test #2:
score: 10
Accepted
time: 522ms
memory: 22600kb
input:
3 60868 87117 3 1 997261313 412700968 717333471 192489438 784392110 821696732 949091933 8361642 752502310 726930970
output:
60292029 640058087 11869095 692950164 540255580 274945329 344271461 515156609 786913720 302417103 43125545 121340671 852329433 394240881 571499679 696088201 191167049 28312047 176057142 187453653 490465175 467256847 482467239 348351209 677628859 813953176 188575598 201611081 640784216 968267076 1413...
result:
ok 60868 lines
Test #3:
score: 10
Accepted
time: 169ms
memory: 22672kb
input:
1 65536 10016911 1 1 997261313 1
output:
95843364 604535263 278366891 990783492 2013628 720647951 9260535 397238127 311690875 773420012 326853860 692389918 315500076 105704504 751724490 885113402 971058219 753283685 830706099 992172799 510959507 779231534 486947229 595061980 133533140 340403360 676742710 506799685 703764431 62824135 798645...
result:
ok 65536 lines
Test #4:
score: 10
Accepted
time: 179ms
memory: 22704kb
input:
1 65536 20544218 1 1 997261313 437647132
output:
644200509 620303851 631204326 481112310 633811411 47942651 870331459 763437565 172267405 581731002 233205140 866042462 774975952 409136314 656136560 476030975 32787014 637953333 511114838 747258841 945232673 153801883 699826168 918103992 547213941 848497521 306040492 225051009 962427223 183330485 51...
result:
ok 65536 lines
Test #5:
score: 10
Accepted
time: 138ms
memory: 22612kb
input:
1 50906 10066288 1 1 776061971 1
output:
587546528 648109148 203519454 618809217 561247059 392172323 324114334 222949490 742797194 547100261 11014982 421541812 582795224 716823937 25648548 214150449 697360571 594557841 651950932 41418218 153610899 204123592 24715666 8410123 759887416 132780989 46436790 632444086 144127670 491389250 5337506...
result:
ok 50906 lines
Test #6:
score: 10
Accepted
time: 141ms
memory: 22576kb
input:
1 50906 14193447 1 1 776061971 7058676
output:
622053597 226388745 107456395 772882966 516527131 362044491 501854798 555831338 617626934 183730318 471355715 54201624 217533864 517954364 272802736 683163272 369123396 272240181 670918454 110963041 632293751 560348804 131349397 328791414 175758401 437413189 5024484 446207973 433731989 733639742 319...
result:
ok 50906 lines
Test #7:
score: 10
Accepted
time: 352ms
memory: 22676kb
input:
2 65536 15489019 1 2 997261313 81819404 229263011 752816130 408725138
output:
948922822 881727936 371493974 295912036 950158243 46531115 439263057 249899778 703170119 106464646 348496160 432112465 428064343 19164663 978200427 773335714 71959766 593295960 82929953 180614969 227338012 401222026 53243774 262385820 745500181 971063406 413682103 441419458 42558924 850605678 568727...
result:
ok 65536 lines
Test #8:
score: 10
Accepted
time: 316ms
memory: 22632kb
input:
2 65536 69511249 1 1 997261313 500289590 382459525 578601485 187892897
output:
701570973 716226039 234558373 409288946 685028963 515183831 272484358 358892317 462512496 531428570 135278492 429845293 258070966 537880616 227630813 850882358 831992488 388830173 716273894 788299005 432448404 551570192 541908616 420756187 464408237 499641174 935462688 689939480 793103718 384814016 ...
result:
ok 65536 lines
Test #9:
score: 10
Accepted
time: 630ms
memory: 22456kb
input:
3 50906 57946722 1 1 776061971 647247752 742197886 79186200 237641887 308607445 80891991 134069917 377341939 143644495
output:
391258133 308185474 168324843 637959251 13075041 222908554 120394561 337546139 312429906 321748004 554021806 667266193 526683824 267035369 686212061 164671063 276963438 625212216 592259777 521994264 739689256 597120742 20522119 267718539 23185084 116169623 360516396 96978312 693315693 674591278 5053...
result:
ok 50906 lines
Test #10:
score: 10
Accepted
time: 652ms
memory: 22408kb
input:
3 50906 93980303 1 2 776061971 505745611 708180844 233942141 7793688 560919932 211232826 486943270 62469440 149793907
output:
229837759 359420333 76590438 374230202 748301690 445720367 122793822 100194533 756172749 331945823 141777464 243199309 246386756 644556570 250294271 101508810 720333206 46422072 153889553 494223906 772263462 469768946 259885781 298581507 401062551 229166351 514521886 398898312 720667125 765488168 29...
result:
ok 50906 lines