UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#205829#3158. 子序列计数Josephcheng1001304ms27772kbC++11984b2024-07-19 19:49:232024-07-19 20:24:25

answer

/*
author: x+b(国外)
*/

#include<bits/stdc++.h>
#define MOD 1000000007
#define N 100005
#define LL long long
using namespace std;

LL n,k,ans;
LL t[N],a[N],dp[N][15],tree[N][15];

LL lowbit(LL a){return a&(-a);}

void add(int t,int p,LL val)
{
	for(int i=t;i<=n;i+=lowbit(i))
		tree[i][p]=(tree[i][p]+val)%MOD;
}

LL sum(int t,int p)
{
	LL res=0;
	for(int i=t;i;i-=lowbit(i))
		res=(res+tree[i][p])%MOD;
	return res;
}

struct node
{
	int id;
	LL val;
}e[N];

bool cmp(node a,node b)
{
	if(a.val==b.val) return a.id>b.id;
	return a.val<b.val;
}

int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]),dp[i][1]=1,e[i]={i,a[i]};
	k++;
	sort(e+1,e+n+1,cmp);
	for(int i=1;i<=n;i++)
		t[i]=e[i].id;
	for(int p=2;p<=k;p++){
		for(int i=1;i<=n;i++){
			dp[t[i]][p]=sum(t[i]-1,p-1)%MOD;
			add(t[i],p-1,dp[t[i]][p-1]);
		}
	}
	for(int i=1;i<=n;i++)
		ans=(ans+dp[i][k])%MOD;
	printf("%lld",ans%MOD);
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 1ms
memory: 1484kb

input:

1000 6
845 371 540 541 334 646 760 501 200 241 586 658 491 773 598 902 665 842 384 807 110 877 994 8...

output:

759594067

result:

ok single line: '759594067'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1492kb

input:

1000 10
846 941 795 636 480 363 861 525 492 970 549 694 469 531 378 762 864 425 357 190 904 145 875 ...

output:

693627455

result:

ok single line: '693627455'

Test #3:

score: 10
Accepted
time: 1ms
memory: 1492kb

input:

1000 8
709 64 456 316 923 716 742 644 18 544 788 534 105 766 842 791 274 799 485 925 496 929 779 13 ...

output:

888798106

result:

ok single line: '888798106'

Test #4:

score: 10
Accepted
time: 43ms
memory: 27768kb

input:

100000 1
91457 94690 89982 40629 60913 39159 31577 34588 97386 43694 34275 85271 72581 91047 30686 2...

output:

501653625

result:

ok single line: '501653625'

Test #5:

score: 10
Accepted
time: 43ms
memory: 27772kb

input:

100000 1
86650 53544 96730 60637 47034 9867 56308 81037 42695 95815 38202 54127 43400 8867 55005 654...

output:

506566375

result:

ok single line: '506566375'

Test #6:

score: 10
Accepted
time: 39ms
memory: 27772kb

input:

100000 1
62703 68040 62364 49510 23990 3889 2826 19621 87482 44980 57815 84673 13539 68084 18044 506...

output:

509436189

result:

ok single line: '509436189'

Test #7:

score: 10
Accepted
time: 163ms
memory: 27768kb

input:

100000 4
29246 94337 54112 92413 22325 73125 4229 37352 69711 71967 52124 27308 57289 87765 36287 15...

output:

695481010

result:

ok single line: '695481010'

Test #8:

score: 10
Accepted
time: 259ms
memory: 27772kb

input:

100000 6
52002 17718 29814 27580 18490 28821 83558 28859 83085 98744 5567 58453 99627 94878 42455 65...

output:

31495056

result:

ok single line: '31495056'

Test #9:

score: 10
Accepted
time: 348ms
memory: 27768kb

input:

100000 8
24149 71611 41388 11918 96005 27576 44736 85293 38251 29037 51462 9244 82984 81652 9768 867...

output:

138675556

result:

ok single line: '138675556'

Test #10:

score: 10
Accepted
time: 407ms
memory: 27772kb

input:

100000 10
39472 76056 58242 12881 24263 35372 7449 45568 16441 59735 86944 23983 74323 67284 86249 7...

output:

642237147

result:

ok single line: '642237147'

Extra Test:

score: 0
Extra Test Passed