1 条题解
-
0
- 注意:子序列不需要连续,所以数组的顺序无关紧要,那我们不妨先把数组排序
- 排序后,如果 能作为某个子序列的最小值,那这样的子序列有多少个呢?
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int P = 998244353; int solve(vector<int>& a) { int n = a.size(); sort(a.begin(), a.end()); vector<int> b(n, 1); for (int i = 1; i < n; i++) b[i] = b[i - 1] * 2 % P; i64 ans = 0; for (int i = 0; i < n; i++) { ans = (ans + (i64) a[i] * b[i] - (i64) a[i] * b[n - 1 - i]) % P; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; cout << solve(a) << '\n'; return 0; }
- 1
信息
- ID
- 164
- 时间
- 100ms
- 内存
- 32MiB
- 难度
- 5
- 标签
- 递交数
- 29
- 已通过
- 15
- 上传者