-
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: 2018-2019 ICPC Southwestern European Regional Program…
…ming Contest (SWERC 2018)
- Loading branch information
Showing
8 changed files
with
444 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,35 @@ | ||
/** | ||
* @file 102465A.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-07-23 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define maxn 1000005 | ||
|
||
bool f[maxn]; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int n, m, cnt = 0, ans = 0; | ||
cin >> n >> m; | ||
for (int i = 1, x; i <= m; i++) { | ||
cin >> x; | ||
for (int j = x; j <= n; j += x) { | ||
if (!f[j]) | ||
cnt++; | ||
else | ||
cnt--; | ||
f[j] = !f[j]; | ||
} | ||
ans = max(ans, cnt); | ||
} | ||
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,35 @@ | ||
/** | ||
* @file 102465B.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-07-23 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define maxn 100005 | ||
|
||
int l[maxn], r[maxn]; | ||
multiset<int> Sl, Sr; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int n; | ||
cin >> n; | ||
for (int i = 1; i <= n; i++) cin >> l[i] >> r[i]; | ||
|
||
int ans = 1; | ||
for (int i = 1, j = 0; i <= n; i++) { | ||
if (j < i) j++, Sl.insert(l[j]), Sr.insert(r[j]); | ||
int len = r[i] - l[i] + 1; | ||
while (j < n && j - i + 1 < len && min(*Sr.begin(), r[j + 1]) - max(*Sl.rbegin(), l[j + 1]) + 1 > j - i + 1) | ||
j++, Sl.insert(l[j]), Sr.insert(r[j]), ans = max(ans, j - i + 1); | ||
Sl.erase(Sl.find(l[i])), Sr.erase(Sr.find(r[i])); | ||
} | ||
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,46 @@ | ||
/** | ||
* @file 102465D.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-07-23 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define maxn 100005 | ||
|
||
vector<int> a[maxn]; | ||
int xu[maxn], xd[maxn]; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int n, m, q, su = 0, sd = 0; | ||
cin >> n >> m >> q; | ||
int64_t cur = n - 1, ans = INT64_MAX; | ||
for (int i = 1, x, y; i <= q; i++) cin >> x >> y, a[y].push_back(x); | ||
|
||
for (int y = m - 1; ~y; y--) | ||
for (auto x : a[y]) { | ||
if (!xu[x]) cur += y * 2, su++; | ||
xu[x]++; | ||
} | ||
|
||
for (int y = 0; y < m; y++) { | ||
ans = min(ans, cur); | ||
for (auto x : a[y]) { | ||
xu[x]--; | ||
if (!xu[x]) su--; | ||
if (!xd[x]) sd++; | ||
xd[x]++; | ||
} | ||
cur += 2 * (sd - su); | ||
} | ||
|
||
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 102465E.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-07-23 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
|
||
#define maxn 10005 | ||
|
||
string a[maxn]; | ||
int v[maxn], vl[maxn], vr[maxn]; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int n, suml = 0, sumr = 0; | ||
cin >> n; | ||
for (int i = 1; i <= n; i++) cin >> a[i] >> v[i], v[i] *= 100, suml += max(0, v[i] - 50), sumr += min(10000, v[i] + 49); | ||
for (int i = 1; i <= n; i++) { | ||
suml -= max(0, v[i] - 50), sumr -= min(10000, v[i] + 49); | ||
vl[i] = max({0, v[i] - 50, 10000 - sumr}), vr[i] = min({10000, v[i] + 49, 10000 - suml}); | ||
if (vl[i] > vr[i]) return cout << "IMPOSSIBLE" << endl, 0; | ||
suml += max(0, v[i] - 50), sumr += min(10000, v[i] + 49); | ||
} | ||
for (int i = 1; i <= n; i++) | ||
cout << a[i] << ' ' << vl[i] / 100 << '.' << vl[i] / 10 % 10 << vl[i] % 10 << ' ' << vr[i] / 100 << '.' | ||
<< vr[i] / 10 % 10 << vr[i] % 10 << 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,62 @@ | ||
/** | ||
* @file 102465G.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-07-23 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define maxn 2505 | ||
#define mod 1000000007 | ||
|
||
typedef pair<int64_t, int64_t> pll; | ||
|
||
vector<pll> a[maxn]; | ||
vector<int64_t> ops[maxn]; | ||
int64_t len[maxn], pre[maxn]; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int n; | ||
cin >> n; | ||
string s; | ||
cin >> s, len[0] = s.size(); | ||
for (int i = 1; i < n; i++) { | ||
string op; | ||
cin >> op; | ||
if (op == "SUB") | ||
ops[i].resize(3), cin >> ops[i][0] >> ops[i][1] >> ops[i][2], len[i] = ops[i][2] - ops[i][1]; | ||
else | ||
ops[i].resize(2), cin >> ops[i][0] >> ops[i][1], len[i] = len[ops[i][0]] + len[ops[i][1]]; | ||
} | ||
|
||
a[n - 1].emplace_back(len[n - 1] - 1, +1); | ||
for (int i = n - 1; i; i--) | ||
if (ops[i].size() == 3) { | ||
int64_t fa = ops[i][0], l = ops[i][1], sum = 0; | ||
for (auto [x, t] : a[i]) a[fa].emplace_back(l + x, t), sum = (sum + t) % mod; | ||
if (l) a[fa].emplace_back(l - 1, mod - sum); | ||
} else { | ||
int64_t f1 = ops[i][0], f2 = ops[i][1], sum = 0; | ||
for (auto [x, t] : a[i]) { | ||
if (x < len[f1]) | ||
a[f1].emplace_back(x, t); | ||
else | ||
sum = (sum + t) % mod, a[f2].emplace_back(x - len[f1], t); | ||
} | ||
if (sum) a[f1].emplace_back(len[f1] - 1, sum); | ||
} | ||
|
||
int64_t ans = 0; | ||
pre[0] = s[0]; | ||
for (int i = 1; i < len[0]; i++) pre[i] = pre[i - 1] + s[i]; | ||
for (auto [x, t] : a[0]) ans = (ans + t * pre[x]) % mod; | ||
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,90 @@ | ||
/** | ||
* @file 102465H.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-07-23 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define maxn 100005 | ||
|
||
typedef pair<int, int> pii; | ||
typedef tuple<int, int, int> tiii; | ||
|
||
class SegmentTree { | ||
private: | ||
struct Node { | ||
Node *l, *r; | ||
set<int> S; | ||
Node(void) { l = r = nullptr; } | ||
}; | ||
|
||
Node *root; | ||
|
||
void insert(Node *&p, int l, int r, int px, int py) { | ||
if (!p) p = new Node(); | ||
p->S.insert(py); | ||
if (l == r) return; | ||
int mid = (l + r) >> 1; | ||
return (px <= mid) ? insert(p->l, l, mid, px, py) : insert(p->r, mid + 1, r, px, py); | ||
} | ||
bool query(Node *&p, int l, int r, int px, int py) { | ||
if (!p) return true; | ||
if (r <= px) return p->S.upper_bound(py) == p->S.begin(); | ||
int mid = (l + r) >> 1; | ||
if (px <= mid) return query(p->l, l, mid, px, py); | ||
return query(p->l, l, mid, px, py) && query(p->r, mid + 1, r, px, py); | ||
} | ||
|
||
public: | ||
SegmentTree(void) { root = nullptr; } | ||
void insert(int x, int y) { return insert(root, 0, 1e8, x, y); } | ||
bool query(int x, int y) { return query(root, 0, 1e8, x, y); } | ||
} ST; | ||
|
||
vector<pii> graph[maxn]; | ||
int dist[3][maxn]; | ||
bool vis[3][maxn]; | ||
priority_queue<pii, vector<pii>, greater<pii>> que; | ||
|
||
void Dijkstra(int S) { | ||
que.emplace(dist[S][S] = 0, S); | ||
while (!que.empty()) { | ||
auto [dis, p] = que.top(); | ||
que.pop(); | ||
if (vis[S][p]) continue; | ||
vis[S][p] = true; | ||
for (auto [i, t] : graph[p]) | ||
if (dist[S][i] > dis + t) que.emplace(dist[S][i] = dis + t, i); | ||
} | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int n, m; | ||
cin >> n >> m; | ||
for (int i = 0, x, y, t; i < m; i++) cin >> x >> y >> t, graph[x].emplace_back(y, t), graph[y].emplace_back(x, t); | ||
memset(dist, 0x3f, sizeof(dist)), Dijkstra(0), Dijkstra(1), Dijkstra(2); | ||
|
||
vector<tiii> cache; | ||
for (int i = 0; i < n; i++) cache.emplace_back(dist[0][i], dist[1][i], dist[2][i]); | ||
sort(cache.begin(), cache.end()); | ||
|
||
int ans = 0; | ||
for (int i = 0, j; i < n; i = j + 1) { | ||
j = i; | ||
while (j + 1 < n && cache[i] == cache[j + 1]) j++; | ||
auto [x, y, z] = cache[i]; | ||
if (!ST.query(y, z)) continue; | ||
ST.insert(y, z), ans += j - i + 1; | ||
} | ||
cout << ans << endl; | ||
|
||
return 0; | ||
} |
Oops, something went wrong.