fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6. inline int power(int a, int b) {
  7. int x = 1;
  8. while (b) {
  9. if (b & 1) x *= a;
  10. a *= a;
  11. b >>= 1;
  12. }
  13. return x;
  14. }
  15.  
  16.  
  17. const int M = 1000000007;
  18. const int N = 3e5+9;
  19. const int INF = 2e9+1;
  20. const int LINF = 2000000000000000001;
  21.  
  22. //_ ***************************** START Below *******************************
  23.  
  24. vector<int> a;
  25.  
  26. int consistency(int n, int m){
  27.  
  28. unordered_map<int,int> freq;
  29. vector<int> b;
  30.  
  31. for(int i=0; i<n; i++){
  32. if(!freq.count(a[i])){
  33. b.push_back(a[i]);
  34. }
  35. freq[a[i]]++;
  36. }
  37.  
  38. sort(begin(b), end(b));
  39. n = b.size();
  40.  
  41.  
  42. int freqM = 1;
  43. int ans = 0;
  44. int total = 0;
  45.  
  46. int s = 0, e = 0;
  47. while(e<n){
  48.  
  49. freqM = (freqM * freq[b[e]])%M;
  50. total = (total + freq[b[e]])%M;
  51.  
  52. if(e-s+1 < m){
  53. e++;
  54. }
  55. else{
  56.  
  57. if(b[e] == b[e-1]+1){
  58. ans = (ans + freqM)%M;
  59. }
  60. freqM /= freq[b[s]];
  61. s++;
  62. e++;
  63. }
  64. }
  65.  
  66. if(m==1) return total;
  67.  
  68. return ans;
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. int practice(int n, int m){
  86.  
  87.  
  88. return 0;
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95. void solve() {
  96.  
  97. int n, m;
  98. cin>> n >> m;
  99.  
  100. a.resize(n);
  101. for(int i=0; i<n; i++) cin >> a[i];
  102.  
  103. cout << consistency(n, m) << endl;
  104.  
  105.  
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112. int32_t main() {
  113. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  114.  
  115. int t = 1;
  116. cin >> t;
  117. while (t--) {
  118. solve();
  119. }
  120.  
  121. return 0;
  122. }
Success #stdin #stdout 0s 5316KB
stdin
9
7 4
8 10 10 9 6 11 7
5 3
4 2 2 3 6
8 2
1 5 2 2 3 1 3 3
3 3
3 3 3
5 1
3 4 3 10 7
12 3
5 2 1 1 4 3 5 5 5 2 7 5
1 1
1
3 2
1 2 3
2 2
1 2
stdout
5
2
10
0
5
11
1
2
1