QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#548081 | #6346. Record Parity | Y2y7m# | WA | 98ms | 34776kb | C++14 | 1.1kb | 2024-09-05 15:18:51 | 2024-09-05 15:18:52 |
Judging History
answer
#include <iostream>
#include <cmath>
using namespace std;
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
const int maxn=1e6+10,mod=998244353;
int n,k;
int a[maxn];
int f[maxn];
int fac[maxn];
int q_pow(int a,int b)
{
int ans=1;
while(b)
{
if(b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
int c[maxn];
int lowbit(int x)
{
return x&(-x);
}
int query(int x)
{
int ans=0;
while(x)
{
ans=max(ans,c[x]);
x-=lowbit(x);
}
return ans;
}
void upd(int x,int d)
{
while(x<=n) c[x]=max(c[x],d),x+=lowbit(x);
}
signed main()
{
ios::sync_with_stdio(false);
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
fac[0]=1;
for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
int pos=n;
for(int i=1;i<=n;i++)
{
f[i]=query(a[i]-1)+1;
upd(a[i],f[i]);
}
int cnt=f[n];
if(k>cnt)
{
cout<<0<<endl;
return 0;
}
int d=0;
if(k%2==0) d=1;
else d=-1;
cout<<(d*fac[cnt]*q_pow(fac[k],mod-2)%mod*q_pow(fac[cnt-k],mod-2)%mod+mod)%mod<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9712kb
input:
5 2 4 1 2 5 3
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 9712kb
input:
7 3 1 2 3 4 5 6 7
output:
998244318
result:
ok 1 number(s): "998244318"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9728kb
input:
5 5 2 5 4 1 3
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 9832kb
input:
10 3 9 7 3 6 10 4 8 2 5 1
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 9712kb
input:
100 76 40 30 48 76 60 22 52 75 31 23 63 86 94 3 45 93 73 37 88 96 77 67 84 85 97 79 25 69 49 47 51 91 58 28 41 53 78 5 46 65 42 56 26 50 64 61 83 29 71 59 9 66 39 32 44 6 8 55 2 54 35 38 72 33 43 99 16 12 62 80 89 98 90 74 87 100 57 11 15 24 7 68 21 27 36 10 92 82 14 95 13 81 20 1 19 17 34 70 18 4
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 98ms
memory: 34776kb
input:
999999 39332 451414 609108 131036 847161 253700 55582 818258 222276 337577 950477 824707 809617 551654 567203 661380 421234 351861 954465 73542 956874 530136 870993 631237 988010 133954 853588 558656 321266 299916 335021 347302 275968 582468 281193 693266 634308 744833 497969 394896 778896 710277 42...
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 97ms
memory: 34772kb
input:
1000000 46282 375837 94088 104451 696764 777873 787329 97811 343419 440438 65609 4790 470282 363111 811237 253643 28392 882823 98152 156690 823537 77896 380936 675851 402343 705542 543953 781400 8146 338069 98261 262758 527678 637070 226497 825938 85884 654134 676334 743404 799028 584462 219375 2467...
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 1ms
memory: 9728kb
input:
10 3 1 3 2 4 6 8 5 9 10 7
output:
998244343
result:
ok 1 number(s): "998244343"
Test #9:
score: 0
Accepted
time: 1ms
memory: 9788kb
input:
10 6 1 2 3 4 5 6 7 8 9 10
output:
210
result:
ok 1 number(s): "210"
Test #10:
score: -100
Wrong Answer
time: 1ms
memory: 9808kb
input:
100 4 1 2 3 6 5 7 4 8 10 12 9 14 11 15 16 13 18 17 19 20 21 23 22 26 25 24 28 27 29 36 30 32 34 33 31 37 35 39 38 41 40 42 44 43 48 46 51 49 45 47 54 50 52 53 57 56 55 58 60 62 59 63 66 61 65 67 69 71 70 72 64 68 75 73 78 74 76 77 80 79 81 82 87 83 86 90 84 88 93 92 96 85 95 94 89 91 98 97 100 99
output:
367290
result:
wrong answer 1st numbers differ - expected: '194580', found: '367290'