𝘛𝘰 𝘣𝘦 𝘢 𝘳𝘰𝘤𝘬, 𝘢𝘯𝘥 𝘯𝘰𝘵 𝘵𝘰 𝘳𝘰𝘭|

园龄:粉丝:关注:

「atcoder - agc054c」Roughly Sorted

link。

高妙题,我只会到构造下界那一步……

构造下界比较容易,只需要注意到交换一次最多让序列向合法迫近一步即可。则答案下界为 imax{(j<i[pj>pi])k,0}

然后需要构造一个映射:排列长相到每个位置的逆序对数量的单射(因为逆序对数量可能不合法……),意即每个位置的逆序对数量唯一决定了排列。证明考虑交换排列任意两项即证。

然后就容易了,cnti>k 不合法,cnti<k 的我们不会去调整(必定劣),只有 cnti=k 时给了我们 ni+1 的操作空间,乘起来即可。

int n, K, a[5100], cnt[5100];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> K;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < i; ++j) cnt[i] += a[j] > a[i];
  }
  int ans = 1;
  for (int i = 1; i <= n; ++i)
    if (cnt[i] == K) ans = 1ll * ans * (n - i + 1) % 998244353;
  cout << ans << "\n";
}

本文作者:𝒸𝒾𝓇𝓃ℴ𝓋𝓈𝓀𝓎

本文链接:https://www.cnblogs.com/orchid-any/p/16603259.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   cirnovsky  阅读(57)  评论(0编辑  收藏  举报
历史上的今天:
2021-08-19 「tricks」平凡二分幻术
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.