5322: [Jxoi2018]排序问题

链接

分析:

  每次选一个出现次数最小的。

代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
#define pa pair<int,int>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
}
const int mod = ;
int fac[], a[], b[]; int ksm(int a,int b) {
int res = ;
while (b) {
if (b & ) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
b >>= ;
}
return res;
}
void solve() {
int n = read(), m = read(), l = read(), r = read(), tot = , cnt = , f = r - l + , ans = ;
for (int i = ; i <= n; ++i) a[i] = read();
sort(a + , a + n + ); for (int i = , j = ; i <= n; i = j) {
while (j <= n && a[i] == a[j]) j ++;
if (l <= a[i] && a[i] <= r) b[++tot] = j - i, f --;
else ans = 1ll * ans * fac[j - i] % mod;
} sort(b + , b + tot + );
for (int i = , j = ; i <= tot; i = j) {
while (j <= tot && b[i] == b[j]) j ++;
++cnt; a[cnt] = b[i], b[cnt] = j - i;
}
a[++cnt] = 1e9, b[cnt] = ; for (int i = , M = m; i <= cnt; ++i) {
LL c = a[i] - a[i - ], t = c * f;
if (t > M) {
int x = a[i - ] + (M / f), y = M % f;
ans = 1ll * ans * ksm(fac[x], f - y) % mod * ksm(fac[x + ], y) % mod;
for (int j = i; j < cnt; ++j)
ans = 1ll * ans * ksm(fac[a[j]], b[j]) % mod;
break;
}
M -= t, f += b[i];
}
ans = 1ll * fac[n + m] * ksm(ans, mod - ) % mod;
printf("%d\n", ans);
}
int main() {
fac[] = ;
for (int i = ; i <= ; ++i) fac[i] = 1ll * fac[i - ] * i % mod;
for (int T = read(); T --; solve());
return ;
}

5322: [Jxoi2018]排序问题的更多相关文章

  1. 【BZOJ5322】[JXOI2018]排序问题(模拟)

    [BZOJ5322][JXOI2018]排序问题(模拟) 题面 BZOJ 洛谷 题解 这题就显得很呆. 显然就是每次找到\([l,r]\)中出现次数最小的那个数并且放一个. 然后随便模拟一下就好了Qw ...

  2. BZOJ5322:[JXOI2018]排序问题——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=5322 https://loj.ac/problem/2543 <-可以看数据,要没有这数据我 ...

  3. 洛谷P4561 [JXOI2018]排序问题(二分 期望)

    题意 题目链接 Sol 首先一种方案的期望等于它一次排好的概率的倒数. 一次排好的概率是个数数题,他等于一次排好的方案除以总方案,也就是\(\frac{\prod cnt_{a_i}!}{(n+m)! ...

  4. [JXOI2018]排序问题

    嘟嘟嘟 这是今天做的第二道九条可怜的题,现在对他的题的印象是:表面清真可做,实则毒瘤坑人. 首先要感谢吉司机,我期望学的特烂,好在样例直接告诉我们期望怎么求了. 令\(b_i\)表示第\(i\)个不同 ...

  5. BZOJ5322: [JXOI2018]排序问题

    传送门 不难看出期望就是 \(\frac{(n+m)!}{\prod_{v=1}^{max}(cnt_v!)}\),\(cnt_v\) 表示 \(v\) 这个数出现的次数. 贪心就是直接把 \(m\) ...

  6. BZOJ5322 JXOI2018排序问题

    对于一个序列,重排后有序的概率显然是∏cnti!/n!,其中cnti为第i种数出现次数.要使概率最小,显然应该让各种数字尽量平均分配.剩下的是div2BC左右的大讨论. #include<ios ...

  7. BZOJ5322 [Jxoi2018]排序问题 【贪心】

    题目链接 BZOJ5322 题解 意思就是使有序的排列尽量少 就是使相同的数尽量少 然后大力贪心即可 #include<algorithm> #include<iostream> ...

  8. 并不对劲的bzoj5322:loj2543:p4561:[JXOI2018]排序问题

    题目大意 \(T\)(\(T\leq10^5\))组询问 每次给出\(n,m,l,r\),和\(n\)个数\(a_1,a_2,...,a_n\),要找出\(m\)个可重复的在区间\([l,r]\)的数 ...

  9. yyb省选前的一些计划

    突然意识到有一些题目的计划,才可以减少大量查水表或者找题目的时间. 所以我决定这样子处理. 按照这个链接慢慢做. 当然不可能只做省选题了. 需要适时候夹杂一些其他的题目. 比如\(agc/arc/cf ...

随机推荐

  1. C++虚函数原理

    类中的成员函数分为静态成员函数和非静态成员函数,而非静态成员函数又分为普通函数和虚函数. Q: 为什么使用虚函数 A: 使用虚函数,我们可以获得良好的可扩展性.在一个设计比较好的面向对象程序中,大多数 ...

  2. 解决 There are no resources that can be added or removed from the server

    网上下载了一个项目,在eclipse中部署时,加载项目到tomcat中项目名称无法显示,报出There are no resources that can be added or removed fr ...

  3. 使用NSOperation以及NSOperationQueue

    使用NSOperation以及NSOperationQueue NSOperation vs. Grand Central Dispatch (GCD) 在Mac OS X v10.6和iOS4之前, ...

  4. CSS背景图片垂直居中center不起效果完美解决

    背景图片居中CSS如下 background:#4892fe url("<%=basePath%>/img/login_bg.jpg") no-repeat cente ...

  5. casperjs,phantomjs,slimerjs and spooky

    1.casperjs http://casperjs.org/ CasperJS is a navigation scripting & testing utility for Phantom ...

  6. python第六课——判断结构

    1.判断结构 格式三: ① if 条件表达式1: 语句块1 elif 条件表达式2: 语句块2 elif 条件表达式3: 语句块3 elif 条件表达式y: 语句块y else: 语句块z ② 执行流 ...

  7. [USACO09JAN]Earthquake Damage

    嘟嘟嘟 刚开始因为没看到只能走没有损坏的农场,磨叽了20多分钟……不管了,写题解吧. 首先如果一个点不能到达原点,那么和他相邻的点也不能到达原点,所以刚开始我们把不能走的点和他相邻的点都打上标记,然后 ...

  8. 上手 Kubernetes

    一.Kubernetes架构 二.重要的几个概念 1.Pod:最小单元 1.1 一个Pod里可以有多个Container 1.2这些container共享这个pod的同一个网络地址,同一个文件系统,通 ...

  9. 【node.js】readline (逐行读取)

    官网链接:http://nodejs.cn/api/readline#readline_readline require('readline') 模块提供了一个接口,用于从可读流(如 process. ...

  10. 基于Naive Bayes算法的文本分类

    理论 什么是朴素贝叶斯算法? 朴素贝叶斯分类器是一种基于贝叶斯定理的弱分类器,所有朴素贝叶斯分类器都假定样本每个特征与其他特征都不相关.举个例子,如果一种水果其具有红,圆,直径大概3英寸等特征,该水果 ...