-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2023-2024 ICPC, Asia Jakarta Regional Contest (Online Mirror, Unrated, ICPC Rules, Teams Preferred)
- Loading branch information
Showing
4 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* @file 1906F.cpp | ||
* @author Macesuted (i@macesuted.moe) | ||
* @date 2024-09-12 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define maxn 1000005 | ||
|
||
typedef pair<int, int> pii; | ||
typedef tuple<int, int, int> tiii; | ||
|
||
class SegmentTree { | ||
private: | ||
struct Node { | ||
int64_t sum, ansl, ansr, ans; | ||
Node(void) { sum = ansl = ansr = ans = 0; } | ||
Node(int64_t v) { sum = ans = ansl = ansr = v; } | ||
Node operator+(const Node& o) const { | ||
Node ans; | ||
ans.sum = this->sum + o.sum; | ||
ans.ansl = max(this->ansl, this->sum + o.ansl); | ||
ans.ansr = max(o.ansr, o.sum + this->ansr); | ||
ans.ans = max({this->ans, o.ans, this->ansr + o.ansl}); | ||
return ans; | ||
} | ||
}; | ||
|
||
Node tree[maxn << 2]; | ||
int n; | ||
|
||
void update(int p, int l, int r, int qp, int v) { | ||
if (l == r) return tree[p] = Node(tree[p].sum + v), void(); | ||
int mid = (l + r) >> 1; | ||
qp <= mid ? update(p << 1, l, mid, qp, v) : update(p << 1 | 1, mid + 1, r, qp, v); | ||
return tree[p] = tree[p << 1] + tree[p << 1 | 1], void(); | ||
} | ||
Node query(int p, int l, int r, int ql, int qr) { | ||
if (ql <= l && r <= qr) return tree[p]; | ||
int mid = (l + r) >> 1; | ||
if (qr <= mid) return query(p << 1, l, mid, ql, qr); | ||
if (ql > mid) return query(p << 1 | 1, mid + 1, r, ql, qr); | ||
return query(p << 1, l, mid, ql, qr) + query(p << 1 | 1, mid + 1, r, ql, qr); | ||
} | ||
|
||
public: | ||
void resize(int _n) { return n = _n, void(); } | ||
void update(int p, int v) { return update(1, 1, n, p, v); } | ||
int64_t query(int l, int r) { return query(1, 1, n, l, r).ans; } | ||
}; | ||
|
||
SegmentTree SGT; | ||
vector<pii> ops[maxn]; | ||
vector<tiii> ques[maxn]; | ||
int a[maxn]; | ||
int64_t ans[maxn]; | ||
|
||
void solve(void) { | ||
int n, m; | ||
cin >> n >> m; | ||
for (int i = 1, l, r, v; i <= m; i++) cin >> l >> r >> v, ops[l].emplace_back(i, v), ops[r + 1].emplace_back(i, -v); | ||
int q; | ||
cin >> q; | ||
for (int i = 1, p, l, r; i <= q; i++) cin >> p >> l >> r, ques[p].emplace_back(i, l, r); | ||
|
||
SGT.resize(m); | ||
for (int i = 1; i <= q; i++) { | ||
for (auto [p, v] : ops[i]) SGT.update(p, v); | ||
for (auto [id, l, r] : ques[i]) ans[id] = SGT.query(l, r); | ||
} | ||
for (int i = 1; i <= q; i++) cout << ans[i] << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int _ = 1; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* @file 1906H.cpp | ||
* @author Macesuted (i@macesuted.moe) | ||
* @date 2024-09-12 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define maxn 200005 | ||
#define mod 998244353 | ||
|
||
int64_t qpow(int64_t a, int64_t x) { | ||
int64_t ans = 1; | ||
while (x) { | ||
if (x & 1) ans = ans * a % mod; | ||
a = a * a % mod, x >>= 1; | ||
} | ||
return ans; | ||
} | ||
int64_t inv(int64_t a) { return qpow(a, mod - 2); } | ||
|
||
int A[30], B[30]; | ||
int64_t fac[maxn], ifac[maxn], f[30][maxn]; | ||
|
||
int64_t C(int n, int m) { return fac[n] * ifac[m] % mod * ifac[n - m] % mod; } | ||
|
||
void solve(void) { | ||
int n, m; | ||
cin >> n >> m; | ||
string SA, SB; | ||
cin >> SA >> SB; | ||
|
||
for (int i = 0; i < n; i++) A[SA[i] - 'A']++; | ||
for (int i = 0; i < m; i++) B[SB[i] - 'A']++; | ||
|
||
int64_t base = 1, sum = 0; | ||
for (int i = 0; i < 26; i++) sum += A[i], base = base * C(sum, A[i]) % mod; | ||
|
||
f[0][B[0]] = 1; | ||
for (int i = 1; i < 26; i++) { | ||
int64_t sum = 0; | ||
for (int j = B[i - 1]; j > A[i - 1]; j--) sum = (sum + f[i - 1][j]) % mod; | ||
for (int j = 0; j <= min(A[i - 1], B[i]); j++) { | ||
sum = (sum + f[i - 1][A[i - 1] - j]) % mod; | ||
f[i][B[i] - j] = sum * C(A[i - 1], j) % mod; | ||
} | ||
} | ||
int64_t ans = 0; | ||
for (int j = A[25]; j <= B[25]; j++) ans = (ans + f[25][j]) % mod; | ||
cout << ans * base % mod << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
fac[0] = ifac[0] = 1; | ||
for (int i = 1; i < maxn; i++) fac[i] = fac[i - 1] * i % mod; | ||
ifac[maxn - 1] = inv(fac[maxn - 1]); | ||
for (int i = maxn - 2; i; i--) ifac[i] = ifac[i + 1] * (i + 1) % mod; | ||
|
||
int _ = 1; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @file 1906J.cpp | ||
* @author Macesuted (i@macesuted.moe) | ||
* @date 2024-09-12 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define maxn 5005 | ||
#define mod 998244353 | ||
|
||
int a[maxn]; | ||
int64_t f[maxn][maxn], g[maxn][maxn], pow2[maxn]; | ||
|
||
void solve(void) { | ||
int n; | ||
cin >> n; | ||
for (int i = 1; i <= n; i++) cin >> a[i]; | ||
|
||
f[1][0] = g[1][0] = 1; | ||
|
||
for (int i = 2; i <= n; i++) { | ||
for (int j = 1; j < i; j++) { | ||
if (a[i - 1] < a[i]) f[i][j] = f[i - 1][j]; | ||
f[i][j] = (f[i][j] + g[i - 1][j - 1]) % mod; | ||
f[i][j] = f[i][j] * pow2[i - j - 1] % mod; | ||
} | ||
for (int j = 1; j < i; j++) g[i][j] = (g[i][j - 1] + f[i][j]) % mod; | ||
} | ||
cout << g[n][n - 1] << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
pow2[0] = 1; | ||
for (int i = 1; i < maxn; i++) pow2[i] = pow2[i - 1] * 2 % mod; | ||
|
||
int _ = 1; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @file 1906M.cpp | ||
* @author Macesuted (i@macesuted.moe) | ||
* @date 2024-09-12 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define maxn 200005 | ||
|
||
int a[maxn]; | ||
|
||
void solve(void) { | ||
int n; | ||
cin >> n; | ||
int64_t sum = 0; | ||
for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i]; | ||
int64_t ans = sum / 3; | ||
for (int i = 1; i <= n; i++) ans = min(ans, sum - a[i]); | ||
cout << ans << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int _ = 1; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |