mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 17:28:47 +00:00
Compare commits
2 Commits
b11f436570
...
e0ae2db0e2
Author | SHA1 | Date | |
---|---|---|---|
e0ae2db0e2 | |||
7bf70ed9bb |
95
S2OJ/1511/1511.cpp
Normal file
95
S2OJ/1511/1511.cpp
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 1e5 + 5;
|
||||||
|
const int mod = 998244353;
|
||||||
|
|
||||||
|
int n, ans = 1;
|
||||||
|
int cnt1, cnt5, cnt7;
|
||||||
|
int cnt2, cnt3, cnt236;
|
||||||
|
int fac[N], inv[N], fac_inv[N];
|
||||||
|
|
||||||
|
inline int C(int n, int m) {
|
||||||
|
return static_cast<long long>(fac[n]) * fac_inv[m] % mod * fac_inv[n - m] % mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
fac[0] = 1;
|
||||||
|
for (int i = 1; i < N; i++) {
|
||||||
|
fac[i] = static_cast<long long>(fac[i - 1]) * i % mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
inv[0] = inv[1] = 1;
|
||||||
|
for (int i = 2; i < N; i++) {
|
||||||
|
inv[i] = static_cast<long long>(mod - (mod / i)) * inv[mod % i] % mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
fac_inv[0] = fac_inv[1] = 1;
|
||||||
|
for (int i = 2; i < N; i++) {
|
||||||
|
fac_inv[i] = static_cast<long long>(fac_inv[i - 1]) * inv[i] % mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
for (int i = 1, x; i <= n; i++) {
|
||||||
|
cin >> x;
|
||||||
|
|
||||||
|
switch (x) {
|
||||||
|
case 1: {
|
||||||
|
cnt1++;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 5: {
|
||||||
|
cnt5++;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 7: {
|
||||||
|
cnt7++;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
case 4:
|
||||||
|
case 8: {
|
||||||
|
cnt2++;
|
||||||
|
cnt236++;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
case 9: {
|
||||||
|
cnt3++;
|
||||||
|
cnt236++;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 6: {
|
||||||
|
cnt236++;
|
||||||
|
ans = static_cast<long long>(ans) * fac[cnt2 + cnt3] % mod * fac_inv[cnt2] % mod * fac_inv[cnt3] % mod;
|
||||||
|
cnt2 = cnt3 = 0;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ans = static_cast<long long>(ans) * fac[cnt2 + cnt3] % mod * fac_inv[cnt2] % mod * fac_inv[cnt3] % mod;
|
||||||
|
ans = static_cast<long long>(ans) * fac[cnt1 + cnt236 + cnt5 + cnt7] % mod * fac_inv[cnt1] % mod * fac_inv[cnt236] % mod * fac_inv[cnt5] % mod * fac_inv[cnt7] % mod;
|
||||||
|
|
||||||
|
cout << ans << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
S2OJ/1511/data/data1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/data9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/data9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1511/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1511/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
72
S2OJ/1512/1512.cpp
Normal file
72
S2OJ/1512/1512.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
int n, a, b, c, d_up = 0, d_down = 0;
|
||||||
|
long long ans = 0;
|
||||||
|
|
||||||
|
cin >> n >> a >> b;
|
||||||
|
|
||||||
|
std::vector<int> nums, x(n);
|
||||||
|
|
||||||
|
for (int& x : x) {
|
||||||
|
cin >> x;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<int> s1;
|
||||||
|
std::multiset<int> s2;
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
s1.insert(x[i]);
|
||||||
|
s2.insert(x[i]);
|
||||||
|
|
||||||
|
if (i == 0) {
|
||||||
|
c = x[i];
|
||||||
|
} else { // i > 0
|
||||||
|
if (c > x[i]) {
|
||||||
|
ans += static_cast<long long>(a) * (c - x[i]);
|
||||||
|
d_down++;
|
||||||
|
} else if (c < x[i]) {
|
||||||
|
ans += static_cast<long long>(b) * (x[i] - c);
|
||||||
|
d_up++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c != *s1.begin()) {
|
||||||
|
auto it = --s1.lower_bound(c);
|
||||||
|
int d = (d_up + s2.count(c)) * b - d_down * a;
|
||||||
|
|
||||||
|
if (d < 0 && c != *it) {
|
||||||
|
ans += static_cast<long long>(d) * (c - *it);
|
||||||
|
d_up += s2.count(c);
|
||||||
|
d_down -= s2.count(*it);
|
||||||
|
c = *it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c != *s1.rbegin()) {
|
||||||
|
auto it = s1.upper_bound(c);
|
||||||
|
int d = (d_down + s2.count(c)) * a - d_up * b;
|
||||||
|
|
||||||
|
if (d < 0 && c != *it) {
|
||||||
|
ans += static_cast<long long>(d) * (*it - c);
|
||||||
|
d_up -= s2.count(*it);
|
||||||
|
d_down += s2.count(c);
|
||||||
|
c = *it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << ans << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
S2OJ/1512/data/data1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/data9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/data9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1512/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1512/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user