ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#205789 | #3158. 子序列计数 | marcuse | 100 | 929ms | 26156kb | C++ | 1.1kb | 2024-07-19 19:08:04 | 2024-07-19 20:18:39 |
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100000 + 10;
const int mod = 1e9 + 7;
int n,k,a[N],ans;
int num[10 + 10][N];
int opt[N][10 + 10];
int read(){
char ch; int sum = 0,flag = 1;
ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-') flag = -flag; ch = getchar();}
while(ch >= '0' && ch <= '9'){sum = sum * 10 + ch - '0'; ch = getchar();}
return flag * sum;
}
int lowbit(int x){
return x & (-x);
}
int query(int x,int id){
int ans = 0;
while(x){
ans = (ans + num[id][x]) % mod;
x -= lowbit(x);
}
return ans;
}
void Add(int x,int id,int val){
while(x <= n){
num[id][x] = (num[id][x] + val) % mod;
x += x & (-x);
}
return ;
}
signed main(){
n = read(); k = read();
k++;
for(int i = 1; i <= n; i++){
a[i] = read();
}
for(int i = 1; i <= n; i++){
opt[i][1] = 1ll;
Add(a[i],1,1);
for(int j = 2; j <= k; j++){
int tmp = query(a[i] - 1,j - 1);
opt[i][j] += (tmp % mod);
Add(a[i],j,opt[i][j]);
}
}
for(int i = 1; i <= n; i++){
ans = (ans % mod + opt[i][k] % mod) % mod;
}
printf("%lld\n",ans % mod);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1396kb
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: 2ms
memory: 1444kb
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: 0ms
memory: 1424kb
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: 46ms
memory: 19120kb
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: 37ms
memory: 19124kb
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: 44ms
memory: 19120kb
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: 101ms
memory: 21464kb
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: 175ms
memory: 23028kb
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: 238ms
memory: 24592kb
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: 286ms
memory: 26156kb
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