QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#253603 | #7766. 栞 | Crysfly | 100 ✓ | 18ms | 9760kb | C++17 | 4.8kb | 2023-11-17 09:51:56 | 2023-11-17 09:51:57 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
//#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 998244353
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define poly vector<modint>
const modint G=3,Ginv=modint(1)/3;
inline poly one(){poly a;a.push_back(1);return a;}
vector<int>rev;
int rts[2100000];
inline int ext(int n){
int k=0;
while((1<<k)<n)++k;return k;
}
inline void init(int k){
int n=1<<k;
rts[0]=1,rts[1<<k]=qpow(31,1<<(21-k)).x;
Rep(i,k,1)rts[1<<(i-1)]=1ull*rts[1<<i]*rts[1<<i]%mod;
For(i,1,n-1)rts[i]=1ull*rts[i&(i-1)]*rts[i&-i]%mod;
}
void ntt(poly&a,int k,int typ){
int n=1<<k;
static ull tmp[2100000];
for(int i=0;i<n;++i)tmp[i]=a[i].x;
if(typ==1){
for(int l=n>>1;l>=1;l>>=1){
ull*k=tmp;
for(int*g=rts;k<tmp+n;k+=(l<<1),++g){
for(ull*x=k;x<k+l;++x){
int o=x[l]%mod*(*g)%mod;
x[l]=*x+mod-o,*x+=o;
}
}
}
for(int i=0;i<n;++i)a[i].x=tmp[i]%mod;
}else{
for(int l=1;l<n;l<<=1){
ull*k=tmp;
for(int*g=rts;k<tmp+n;k+=(l<<1),++g){
for(ull*x=k;x<k+l;++x){
int o=x[l]%mod;
x[l]=(*x+mod-o)*(*g)%mod,*x+=o;
}
}
}
int iv=qpow(n,mod-2).x;
for(int i=0;i<n;++i)a[i].x=tmp[i]%mod*iv%mod;
reverse(a.begin()+1,a.end());
}
}
poly operator +(poly a,poly b){
int n=max(a.size(),b.size());a.resize(n),b.resize(n);
For(i,0,n-1)a[i]+=b[i];return a;
}
poly operator -(poly a,poly b){
int n=max(a.size(),b.size());a.resize(n),b.resize(n);
For(i,0,n-1)a[i]-=b[i];return a;
}
poly operator *(poly a,modint b){
int n=a.size();
For(i,0,n-1)a[i]*=b;return a;
}
poly operator *(poly a,poly b){
if(!a.size()||!b.size())return {};
if((int)a.size()<=32 || (int)b.size()<=32){
poly c(a.size()+b.size()-1,0);
for(int i=0;i<a.size();++i)for(int j=0;j<b.size();++j)c[i+j]+=a[i]*b[j];
return c;
}
int n=(int)a.size()+(int)b.size()-1,k=ext(n);
a.resize(1<<k),b.resize(1<<k);
ntt(a,k,1),ntt(b,k,1);
For(i,0,(1<<k)-1)a[i]*=b[i];
ntt(a,k,-1),a.resize(n);return a;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 2000005
#define inf 0x3f3f3f3f
int n,k,p[505];
poly f,g[505];
signed main()
{
init(15);
n=read(),k=read();
initC(n+1);
f.resize(n+1);
For(i,1,n){
f[i]=fac[i];
For(j,1,i-1)f[i]-=f[j]*fac[i-j];
}
g[0].resize(n+1),g[0][0]=1;
For(i,1,n)g[i]=g[i-1]*f,g[i].resize(n+1);
bool fl=1;
For(i,1,n)p[i]=read();
For(i,1,n)if(p[i]!=i)fl=0;
if(fl){
modint res=0;
For(i,k,n)res+=g[i][n];
cout<<res.x;
exit(0);
}
For(i,1,n)
if(p[i]>p[i+1]){
modint res=0;
if(k>n-i)res+=g[k-(n-i)][i];
if(p[i]<p[i+2]){
For(j,i+2,n){
if(p[j]<=p[j-1])break;
if(k>n-j+1)res+=g[k-(n-j+1)][i]*fac[j-i-1];
}
}
cout<<res.x;
exit(0);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 5780kb
input:
6 1 1 2 3 4 5 6
output:
720
result:
ok 1 number(s): "720"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5804kb
input:
6 3 1 2 5 3 4 6
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5800kb
input:
6 3 1 2 4 3 6 5
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5780kb
input:
6 5 1 2 3 5 4 6
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 0ms
memory: 5776kb
input:
6 5 1 2 3 5 4 6
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 1ms
memory: 6012kb
input:
6 4 1 3 2 4 6 5
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5808kb
input:
6 5 1 3 2 5 4 6
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5940kb
input:
6 3 1 2 3 6 5 4
output:
13
result:
ok 1 number(s): "13"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5972kb
input:
6 4 1 2 5 4 3 6
output:
3
result:
ok 1 number(s): "3"
Test #10:
score: 0
Accepted
time: 1ms
memory: 5780kb
input:
6 3 1 2 5 4 3 6
output:
0
result:
ok 1 number(s): "0"
Subtask #2:
score: 20
Accepted
Dependency #1:
100%
Accepted
Test #11:
score: 20
Accepted
time: 1ms
memory: 5800kb
input:
9 9 1 2 3 4 5 6 7 8 9
output:
1
result:
ok 1 number(s): "1"
Test #12:
score: 0
Accepted
time: 1ms
memory: 6004kb
input:
9 3 1 2 3 4 5 6 9 7 8
output:
3447
result:
ok 1 number(s): "3447"
Test #13:
score: 0
Accepted
time: 1ms
memory: 5936kb
input:
9 7 1 3 2 4 6 5 7 8 9
output:
3
result:
ok 1 number(s): "3"
Test #14:
score: 0
Accepted
time: 1ms
memory: 6012kb
input:
9 5 1 2 3 4 5 6 7 9 8
output:
531
result:
ok 1 number(s): "531"
Test #15:
score: 0
Accepted
time: 0ms
memory: 5964kb
input:
9 9 1 4 3 2 5 6 7 8 9
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 1ms
memory: 5716kb
input:
9 2 1 2 3 4 5 6 7 9 8
output:
29093
result:
ok 1 number(s): "29093"
Test #17:
score: 0
Accepted
time: 1ms
memory: 5712kb
input:
9 4 1 2 3 4 5 6 7 9 8
output:
2109
result:
ok 1 number(s): "2109"
Test #18:
score: 0
Accepted
time: 1ms
memory: 5744kb
input:
9 8 1 2 3 5 4 7 6 8 9
output:
4
result:
ok 1 number(s): "4"
Test #19:
score: 0
Accepted
time: 1ms
memory: 5716kb
input:
9 7 1 2 3 4 5 7 6 9 8
output:
23
result:
ok 1 number(s): "23"
Test #20:
score: 0
Accepted
time: 1ms
memory: 5804kb
input:
9 7 1 2 3 4 5 7 6 9 8
output:
23
result:
ok 1 number(s): "23"
Subtask #3:
score: 30
Accepted
Test #21:
score: 30
Accepted
time: 17ms
memory: 8024kb
input:
500 369 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
151242732
result:
ok 1 number(s): "151242732"
Test #22:
score: 0
Accepted
time: 17ms
memory: 8028kb
input:
500 261 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
175105582
result:
ok 1 number(s): "175105582"
Test #23:
score: 0
Accepted
time: 17ms
memory: 7828kb
input:
500 79 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
328555836
result:
ok 1 number(s): "328555836"
Test #24:
score: 0
Accepted
time: 17ms
memory: 7828kb
input:
500 306 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
738246233
result:
ok 1 number(s): "738246233"
Test #25:
score: 0
Accepted
time: 12ms
memory: 7804kb
input:
500 291 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
90157368
result:
ok 1 number(s): "90157368"
Test #26:
score: 0
Accepted
time: 17ms
memory: 7820kb
input:
500 268 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
582110163
result:
ok 1 number(s): "582110163"
Test #27:
score: 0
Accepted
time: 17ms
memory: 7800kb
input:
500 295 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
551109392
result:
ok 1 number(s): "551109392"
Test #28:
score: 0
Accepted
time: 17ms
memory: 8016kb
input:
500 137 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
709320534
result:
ok 1 number(s): "709320534"
Test #29:
score: 0
Accepted
time: 18ms
memory: 7828kb
input:
500 66 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
735053639
result:
ok 1 number(s): "735053639"
Test #30:
score: 0
Accepted
time: 13ms
memory: 7960kb
input:
500 233 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
676167049
result:
ok 1 number(s): "676167049"
Subtask #4:
score: 40
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #31:
score: 40
Accepted
time: 17ms
memory: 7816kb
input:
500 198 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
830163792
result:
ok 1 number(s): "830163792"
Test #32:
score: 0
Accepted
time: 14ms
memory: 7696kb
input:
500 432 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 80 78 79 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
409343845
result:
ok 1 number(s): "409343845"
Test #33:
score: 0
Accepted
time: 17ms
memory: 7800kb
input:
500 265 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
194041644
result:
ok 1 number(s): "194041644"
Test #34:
score: 0
Accepted
time: 17ms
memory: 7796kb
input:
500 173 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
526227080
result:
ok 1 number(s): "526227080"
Test #35:
score: 0
Accepted
time: 12ms
memory: 7804kb
input:
500 483 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
614441401
result:
ok 1 number(s): "614441401"
Test #36:
score: 0
Accepted
time: 13ms
memory: 8032kb
input:
500 243 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
284882224
result:
ok 1 number(s): "284882224"
Test #37:
score: 0
Accepted
time: 17ms
memory: 9624kb
input:
500 282 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
308933889
result:
ok 1 number(s): "308933889"
Test #38:
score: 0
Accepted
time: 18ms
memory: 7756kb
input:
500 231 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
131213230
result:
ok 1 number(s): "131213230"
Test #39:
score: 0
Accepted
time: 13ms
memory: 9760kb
input:
500 415 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 100 99 ...
output:
590026968
result:
ok 1 number(s): "590026968"
Test #40:
score: 0
Accepted
time: 13ms
memory: 7800kb
input:
500 344 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
124432123
result:
ok 1 number(s): "124432123"