LOADING

加载过慢请开启缓存,浏览器默认开启

daily 2

2023/9/6

CF 1696E

ll quick_pow(ll x,ll exp,int p)
{
      ll ans=1;
      while(exp)
      {
        if(exp&1)ans=ans*x%p;
        exp>>=1;
        x=x*x%p;
      }
      return ans;
}
ll inv[MAXN],fac[MAXN];
void init(int n,int p)
{
  memset(inv,0,sizeof(inv));
  memset(fac,0,sizeof(fac));
  inv[0]=fac[0]=1;
  for(int i=1;i<=n;++i)
  {
    fac[i]=fac[i-1]*i%p;
  }
  inv[n]=quick_pow(fac[n],p-2,p)%p;
  for(int i=n;i>=1;--i)inv[i-1]=inv[i]*i%p;
}
ll C(ll n,ll m,ll p)
{
  if(m>n||m<0)return 0;
  return fac[n]*inv[n-m]%p*inv[m]%p;
}
void solve() {
  int n;
  cin >> n;
  ++n;
  vector<ll> a(n + 1);
  for (int i = 1 ; i <= n; ++i) {
    cin >> a[i];
  } 
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = (ans + C(a[i] + i - 1, a[i] - 1, MOD)) %MOD;
  }
  cout << ans << '\n';
  return ;
}

CF 1699C

void solve() {
  int n;
  cin >> n;
  vector<int> a(n), pos(n);
  for (int i = 0; i <= n - 1; ++i) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  int l = pos[0], r = pos[0];
  ll ans = 1;
  for (int i = 1; i <= n - 1; ++i) {
    if (pos[i] < l) {
      l = pos[i];
    } else if (pos[i] > r) {
      r = pos[i];
    } else {
      ans = ans * (r - l + 1 - i) % MOD;
    }
  }
  cout << ans << '\n';
  return ;
}