B. Duff in Beach
time limit per test
memory limit per test
input
output
b0, b1, ..., bl - 1 consisting of l positive integers. This array was strange because it was extremely long, but there was another (maybe shorter) array, a0, ..., an - 1 that b can be build from a with formula: bi = ai mod n where a mod b denoted the remainder of dividing a by b.
b like bi1, bi2, ..., bix (0 ≤ i1 < i2 < ... < ix < l), such that:
- 1 ≤ x ≤ k
- 1 ≤ j ≤ x - 1,
- 1 ≤ j ≤ x - 1, bij ≤ bij + 1. i.e this subsequence is non-decreasing.
109.
Duff is not a programmer, and Malek is unavailable at the moment. So she asked for your help. Please tell her this number.
Input
n, l and k (1 ≤ n, k, n × k ≤ 106 and 1 ≤ l ≤ 1018).
n space separated integers, a0, a1, ..., an - 1 (1 ≤ ai ≤ 109 for each 0 ≤ i ≤ n - 1).
Output
1 000 000 007
Examples
input
3 5 3 5 9 1
output
10
input
5 10 3 1 2 3 4 5
output
25
#include <bits/stdc++.h>
#define maxn 1000005
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll dp[maxn], a[maxn], sum[maxn], c[maxn];
int b[maxn];
int main(){
// freopen("in.txt", "r", stdin);
ll n, l, k;
scanf("%I64d%I64d%I64d", &n, &l, &k);
for(int i = 1; i <= n; i++){
scanf("%I64d", a+i);
c[i] = a[i];
}
sort(a+1, a+n+1);
int h = 1;
for(int i = 2; i <= n; i++){
if(a[i] != a[i-1]){
for(int j = h; j < i; j++){
b[j] = i-1;
}
h = i;
}
}
for(int j = h; j <= n; j++){
b[j] = n;
}
ll ans = 0;
for(int i = 1; i <= k * n; i++){
int h = i % n == 0 ? n : i % n;
(dp[i] = sum[b[h]] + 1) %= MOD;
(sum[h] = sum[h-1] + dp[i]) %= MOD;
}
ll e = l / n;
h = min(e*n, k*n);
for(int i = 1; i <= h; i++){
(ans += dp[i]) %= MOD;
}
ll v = 0;
if(e > k){
for(int i = (k-1)*n+1; i <= k*n; i++){
(v += dp[i]) %= MOD;
}
ans += v % MOD * ((e - k) % MOD) % MOD;
ans %= MOD;
}
if(l % n){
e++;
e = min(e, k);
v = l % n;
for(int i = 1; i <= v; i++){
int m = lower_bound(a+1, a+n, c[i]) - a;
(ans += dp[(e-1)*n+m]) %= MOD;
}
}
printf("%I64d\n", ans);
return 0;
}