-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Codeforces Gym: 2019-2020 ACM-ICPC Latin American Regional Programmin…
…g Contest
- Loading branch information
Showing
10 changed files
with
537 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,95 @@ | ||
/** | ||
* @file 102428C.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-07-25 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
|
||
#define maxn 100005 | ||
|
||
class SegmentTree { | ||
private: | ||
struct Node { | ||
int vl, vr, delt; | ||
}; | ||
|
||
Node tree[maxn << 2]; | ||
int n; | ||
|
||
void pushUp(int p) { | ||
int pl = tree[p << 1 | 1].vl - tree[p << 1].delt, pr = tree[p << 1 | 1].vr - tree[p << 1].delt; | ||
tree[p].delt = tree[p << 1].delt + tree[p << 1 | 1].delt; | ||
if (tree[p << 1].vl > pr) return tree[p].vl = tree[p].vr = pr, void(); | ||
if (tree[p << 1].vr < pl) return tree[p].vl = tree[p].vr = pl, void(); | ||
tree[p].vl = max(tree[p << 1].vl, pl), tree[p].vr = min(tree[p << 1].vr, pr); | ||
return; | ||
} | ||
void build(int p, int l, int r, int vl, int vr, int a[]) { | ||
if (l == r) { | ||
if (a[l] > 0) | ||
a[l] = min(a[l], vr - vl); | ||
else | ||
a[l] = max(a[l], vl - vr); | ||
tree[p].vl = vl, tree[p].vr = vr, tree[p].delt = a[l]; | ||
if (a[l] > 0) | ||
tree[p].vr -= a[l]; | ||
else | ||
tree[p].vl -= a[l]; | ||
return; | ||
} | ||
int mid = (l + r) >> 1; | ||
build(p << 1, l, mid, vl, vr, a), build(p << 1 | 1, mid + 1, r, vl, vr, a); | ||
return pushUp(p); | ||
} | ||
int query(int p, int l, int r, int ql, int qr, int v) { | ||
if (ql <= l && r <= qr) return min(max(v, tree[p].vl), tree[p].vr) + tree[p].delt; | ||
int mid = (l + r) >> 1; | ||
if (ql <= mid) v = query(p << 1, l, mid, ql, qr, v); | ||
if (qr > mid) v = query(p << 1 | 1, mid + 1, r, ql, qr, v); | ||
return v; | ||
} | ||
void print(int p, int l, int r) { | ||
cerr << "# " << p << ' ' << l << ' ' << r << endl; | ||
cerr << tree[p].vl << ' ' << tree[p].vr << ' ' << tree[p].delt << endl; | ||
if (l == r) return; | ||
int mid = (l + r) >> 1; | ||
print(p << 1, l, mid), print(p << 1 | 1, mid + 1, r); | ||
return; | ||
} | ||
|
||
public: | ||
void build(int n_, int vl, int vr, int a[]) { return build(1, 1, n = n_, vl, vr, a); } | ||
int query(int l, int r, int v) { return query(1, 1, n, l, r, v); } | ||
void print(void) { return print(1, 1, n); } | ||
} ST; | ||
|
||
int a[maxn]; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int n, vl, vr; | ||
cin >> n >> vl >> vr; | ||
for (int i = 1; i <= n; i++) cin >> a[i]; | ||
|
||
ST.build(n, vl, vr, a); | ||
|
||
// ST.print(); | ||
|
||
int q; | ||
cin >> q; | ||
while (q--) { | ||
int l, r, v; | ||
cin >> l >> r >> v; | ||
cout << ST.query(l, r, v) << endl; | ||
} | ||
|
||
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,50 @@ | ||
/** | ||
* @file 102428D.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-07-25 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define maxn 1005 | ||
|
||
typedef pair<double, int> pdi; | ||
|
||
const double PI = acos(-1); | ||
|
||
int x[maxn], y[maxn], w[maxn]; | ||
|
||
int n; | ||
|
||
map<double, int> S; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr); | ||
|
||
cin >> n; | ||
for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> w[i]; | ||
|
||
S[0] = 0; | ||
for (int i = 1; i <= n; i++) | ||
for (int j = 1; j <= n; j++) { | ||
if (w[i] <= w[j]) continue; | ||
double f = atan2(y[j] - y[i], x[j] - x[i]); | ||
double fl = f + 0.5 * PI + 1e-6, fr = f + 1.5 * PI - 1e-6; | ||
if (fl > 2 * PI) fl -= 2 * PI, fr -= 2 * PI; | ||
if (fl < 0) fl += 2 * PI, fr += 2 * PI; | ||
if (fr > 2 * PI) | ||
S[fl]++, S[0]++, S[fr - 2 * PI]--; | ||
else | ||
S[fl]++, S[fr]--; | ||
} | ||
|
||
int cnt = 0; | ||
for (auto [v, d] : S) | ||
if ((cnt += d) == 0) return cout << "Y" << endl, 0; | ||
cout << "N" << endl; | ||
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,38 @@ | ||
/** | ||
* @file 102428E.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-07-25 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define maxn 100005 | ||
|
||
string s; | ||
vector<int> a; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr); | ||
|
||
cin >> s; | ||
int n = s.size(), m; | ||
cin >> m; | ||
|
||
for (int i = 0; i < n; i++) | ||
if (s[i] == 'E') a.push_back(i); | ||
int len = a.size(); | ||
for (int i = 0; i < len; i++) a.push_back(a[i] + n); | ||
for (int i = 0; i < len; i++) a.push_back(a[i] + 2 * n); | ||
|
||
int64_t ans = 0; | ||
for (int i = len; i < 2 * len; i++) { | ||
int l = a[i] - a[i - 1], c = min(l, m); | ||
ans += int64_t(m + (m - c + 1)) * c / 2; | ||
} | ||
cout << ans << endl; | ||
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,37 @@ | ||
/** | ||
* @file 102428F.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-07-25 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define maxn 5005 | ||
#define mod 1000000007 | ||
|
||
int64_t f[maxn][maxn], g1[maxn][maxn], g2[maxn][maxn]; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr); | ||
|
||
int n, m; | ||
cin >> n >> m, m -= n; | ||
|
||
f[m][n] = 1; | ||
for (int i = 1; i <= n; i++) g1[m][i] = 1, g2[m][i] = n; | ||
|
||
for (int i = m - 1; ~i; i--) { | ||
for (int j = 1; j <= n && i + j <= m; j++) { | ||
f[i][j] = (g2[i + j][j] + (mod - j + 1) * g1[i + j][j]) % mod; | ||
} | ||
for (int j = m; j; j--) g1[i][j] = (g1[i][j + 1] + f[i][j]) % mod, g2[i][j] = (g2[i][j + 1] + f[i][j] * j) % mod; | ||
} | ||
|
||
cout << g1[0][1] << endl; | ||
|
||
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,77 @@ | ||
/** | ||
* @file 102428G.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-07-25 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
|
||
#define maxn 200005 | ||
|
||
class StringAutomaton { | ||
private: | ||
struct Node { | ||
Node *son[26], *link; | ||
int len; | ||
Node(void) { memset(son, 0, sizeof(son)), link = nullptr, len = 0; } | ||
}; | ||
|
||
Node *root, *last; | ||
|
||
public: | ||
StringAutomaton(void) { root = last = new Node(); } | ||
void pushBack(char c) { | ||
int v = c - 'A'; | ||
auto p = last, np = new Node(); | ||
np->len = p->len + 1; | ||
while (p && !p->son[v]) p->son[v] = np, p = p->link; | ||
if (!p) | ||
np->link = root; | ||
else { | ||
auto q = p->son[v]; | ||
if (p->len + 1 == q->len) | ||
np->link = q; | ||
else { | ||
auto t = new Node(); | ||
*t = *q, t->len = p->len + 1; | ||
while (p && p->son[v] == q) p->son[v] = t, p = p->link; | ||
np->link = q->link = t; | ||
} | ||
} | ||
last = np; | ||
return; | ||
} | ||
int solve(string s) { | ||
queue<int> que; | ||
for (auto c : s) que.push(c - 'A'); | ||
int ans = 0; | ||
while (!que.empty()) { | ||
ans++; | ||
bool work = false; | ||
auto p = root; | ||
while (!que.empty() && p->son[que.front()]) p = p->son[que.front()], que.pop(), work = true; | ||
if (!work) return -1; | ||
} | ||
return ans; | ||
} | ||
} SAM; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
string s; | ||
cin >> s; | ||
for (auto c : s) SAM.pushBack(c); | ||
|
||
int q; | ||
cin >> q; | ||
while (q--) cin >> s, cout << SAM.solve(s) << endl; | ||
|
||
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,63 @@ | ||
/** | ||
* @file 102428H.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-07-25 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
double f[100][100][100]; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr); | ||
|
||
for (int i = 0; i < 75; i++) f[75][i][0] = 1; | ||
|
||
auto sum = [&](int i, int j, int k) { | ||
double tot = 0; | ||
for (int t = 2; t <= 6; t++) { | ||
if (i + k + t <= 75) | ||
tot += f[i][j][k + t]; | ||
else | ||
tot += 1 - f[j][i][0]; | ||
} | ||
return tot; | ||
}; | ||
|
||
for (int s = 148; ~s; s--) | ||
for (int i = 74; ~i; i--) { | ||
int j = s - i; | ||
if (j < 0 || j > 74 || i > j) continue; | ||
|
||
double l = 0, r = 1; | ||
while (l + 1e-8 < r) { | ||
double m = (l + r) / 2; | ||
f[i][j][0] = m; | ||
|
||
for (int k = 75 - j; k >= 2; k--) f[j][i][k] = max(1 - f[i][j + k][0], (1 - f[i][j][0] + sum(j, i, k)) / 6); | ||
f[j][i][0] = (1 - f[i][j][0] + sum(j, i, 0)) / 6; | ||
|
||
if (i != j) { | ||
for (int k = 75 - i; k >= 2; k--) f[i][j][k] = max(1 - f[j][i + k][0], (1 - f[j][i][0] + sum(i, j, k)) / 6); | ||
f[i][j][0] = (1 - f[j][i][0] + sum(i, j, 0)) / 6; | ||
} | ||
|
||
(f[i][j][0] < m ? r : l) = m; | ||
} | ||
} | ||
|
||
int q; | ||
cin >> q; | ||
while (q--) { | ||
int i, j, k; | ||
cin >> i >> j >> k; | ||
double v1 = 1 - f[j][i + k][0], v2 = (1 - f[j][i][0] + sum(i, j, k)) / 6; | ||
cout << "CH"[v1 > v2] << endl; | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.