Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int LL;
  4. LL t[65536][10];
  5. LL p[10];
  6. const int mod = 1e9;
  7. void add (int a) {
  8.     for (int i=0; i<10; i++)
  9.         p[i]=(p[i]+t[a][i])%mod;
  10. }
  11. void calculate (int a, int b) {
  12.     for (int i=0; i<10; i++)
  13.         p[i]=0LL;
  14.     while (a <= b) {
  15.         if (a&1)
  16.             add(a++);
  17.         if (!(b&1))
  18.             add(b--);
  19.         a/=2;
  20.         b/=2;
  21.     }
  22. }
  23. void update (int a) {
  24.     a/=2;
  25.     while (a) {
  26.         for (int i=0; i<10; i++)
  27.             t[a][i]=t[a*2][i]+t[a*2+1][i];
  28.         a/=2;
  29.     }
  30. }
  31. void insert (int a, int bs, int n) {
  32.     calculate (bs+a, bs+n-1);
  33.     for (int i=8; i>=0; i--)
  34.         p[i+1]=p[i];
  35.     p[0]=1;
  36.     for (int i=0; i<10; i++)
  37.         t[a+bs-1][i]=p[i];
  38.     update (bs+a-1);
  39. }
  40. int main () {
  41.     int n, k, x, bs;
  42.     scanf ("%d%d", &n, &k);
  43.     bs=1;
  44.     while (bs<n) bs*=2;
  45.     for (int i=0; i<n; i++) {
  46.         scanf ("%d", &x);
  47.         insert (x, bs, n);
  48.     }
  49.     LL wyn=0;
  50.     for (int i=bs; i<bs+n; i++)
  51.         wyn=(wyn+t[i][k-1])%mod;
  52.     printf ("%lld", wyn);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement