首页 > 其他分享 >「atcoder - agc054c」Roughly Sorted

「atcoder - agc054c」Roughly Sorted

时间:2022-08-19 20:44:07浏览次数:93  
标签:atcoder cnt int sum Roughly 下界 agc054c 5100 逆序

link。

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

构造下界比较容易,只需要注意到交换一次最多让序列向合法迫近一步即可。则答案下界为 \(\sum_i \max\{\left(\sum_{j < i} [p'_j > p'_i]\right)-k, 0\}\)。

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

然后就容易了,\(cnt_i > k\) 不合法,\(cnt_i < k\) 的我们不会去调整(必定劣),只有 \(cnt_i = k\) 时给了我们 \(n-i+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";
}

标签:atcoder,cnt,int,sum,Roughly,下界,agc054c,5100,逆序
From: https://www.cnblogs.com/orchid-any/p/16603259.html

相关文章

  • AtCoder 比赛记录
    ARC140打得很烂。Rank590,Performance1696。D-OnetoOne每个点都有恰好一个出边,所以这是一个外向基环森林。因此连通块数就等于环的个数,我们只需要求出所有方案中......
  • AtCoder Beginner Contest 258
    A-When?问21:00后的第k分钟的时间#include<bits/stdc++.h>usingnamespacestd;constintN=2e5+5;intn,a[N],cnt,k;int32_tmain(){ intn,h=21......
  • Atcoder ABC169
    A  直接输出\(a×b\)即可inta,b;std::cin>>a>>b;std::cout<<a*b<<"\n";B  将所有的\(N\)个数乘起来看是不是大于\(10^{18}\),很明......
  • AtCoder Beginner Contest 264部分题解(a~d)
    A题题目大意:打印“atcoder"中从第l个到第r个字母参考代码:#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong#defineIOSios_base::sync_with_std......
  • Atcoder Grand Contest 025 E - Walking on a Tree(欧拉回路)
    Atcoder题面传送门打个表发现答案等于每条边被覆盖的次数与\(2\)取min之和,考虑如何构造这个上界。首先考虑树是以\(1\)为中心的菊花图,且任意\(A_i,B_i\ne1\)的......
  • 【杂题乱写】AtCoder dp 26题
    AtCoderdp26题原比赛链接洛谷题单链接A-Frog1题目已然给出了转移方程,设\(dp_i\)为到第\(i\)块石头的最小代价。转移方程:\[dp_i=\min(dp_{i-1}+|h_i-h_{i-1}......
  • freee Programming Contest 2022(AtCoder Beginner Contest 264)A-E
    freeeProgrammingContest2022(AtCoderBeginnerContest264)https://atcoder.jp/contests/abc264FG待补A-"atcoder".substr()输出atcoder第L位和第R位上的字符#in......
  • AtCoder Beginner Contest 264
    比赛链接AtCoderBeginnerContest264E.Blackout2给出很多点(\(n+m\leq2\times10^5\)),有发电站和城市,以及很多边(\(e\leq5\times10^5\)),有\(q\)次删边操作,求每次......
  • AtCoder Beginner Contest 264
    E-Blackout2离线+并查集。注意到只有删边操作,而删边操作其实不是很好维护。由于没有强制在线,所以可以离线一下然后逆序考虑,这样删边就变成了加边,这就用并查集就足以维......