CF1418E. Expected Damage

不想写题意

一定要单独考虑。

这种排列组合,一定要考虑概率,首先$\leq b$一定可以$1-\frac{a}{big}$

然后小的一定要单独考虑$big+1$个间隙不能选择$a$种。

一定要单独考虑

代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mk make_pair
const int N = 1e6 + 10;
const int mod = 998244353;
int read()
{
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + c - '0', c = getchar();
return x * f;
}

int inc(int x, int y) { return (x + y >= mod) ? (x + y - mod) : (x + y); }
int del(int x, int y) { return (x - y < 0) ? (x - y + mod) : (x - y); }
int qpow(int a, int x, int mo)
{
int res = 1;
while (x)
{
if (x & 1)
res = 1ll * a * res % mo;
a = 1ll * a * a % mo;

x >>= 1;
}
return res;
}
int d[N];
int sum[N];
int main()
{
int n = read(), m = read();
for (int i = 1; i <= n; i++)
d[i] = read();
sort(1 + d, 1 + d + n);
for (int i = 1; i <= n; i++)
sum[i] = inc(sum[i - 1], d[i] % mod);
for (int i = 1; i <= m; i++)
{
int a = read(), b = read();
int k = lower_bound(1 + d, 1 + d + n, b) - d;
k--;
int big = n - k;
if (big < a)
{
puts("0");
}
else
{
int ans = 0;

ans = inc(1ll * del(sum[n], sum[k]) * (big - a) % mod * qpow(big, mod - 2, mod) % mod, ans);
ans = inc(1ll * sum[k] * (big + 1 - a) % mod * qpow(big + 1, mod - 2, mod) % mod, ans);
cout << ans << endl;
}
}
}