Skip to content

Commit c23bc0a

Browse files
committed
Codeforces Gym: The 2025 ICPC Latin America Championship
1 parent e534831 commit c23bc0a

File tree

6 files changed

+543
-0
lines changed

6 files changed

+543
-0
lines changed

Codeforces Gym/105789B.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @file 105789B.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-03-20
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
using bs = bitset<1505>;
20+
21+
bs base[1505], ids[1505];
22+
bool vis[1505];
23+
int n, m;
24+
25+
void insert(int id, bs v) {
26+
bs cid;
27+
cid.set(id);
28+
for (int i = 0; i <= m; i++) {
29+
if (!v[i]) continue;
30+
if (!vis[i]) {
31+
base[i] = v, ids[i] = cid, vis[i] = true;
32+
return;
33+
}
34+
v ^= base[i], cid ^= ids[i];
35+
}
36+
int c = cid.count() / 2;
37+
for (int b = 1, p = 0; b <= n; b++) p += cid[b], cout << (cid[b] ? (1 + (p > c)) : 0);
38+
cout << endl;
39+
exit(0);
40+
}
41+
42+
void solve(void) {
43+
cin >> n >> m;
44+
for (int i = 1; i <= n; i++) {
45+
string s;
46+
cin >> s;
47+
bs v;
48+
v.set(0);
49+
for (int j = 0; j < m; j++) v[j + 1] = s[j] - '0';
50+
insert(i, v);
51+
}
52+
cout << '*' << endl;
53+
return;
54+
}
55+
56+
bool mem2;
57+
58+
int main() {
59+
ios::sync_with_stdio(false), cin.tie(nullptr);
60+
#ifdef LOCAL
61+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
62+
#endif
63+
64+
int _ = 1;
65+
while (_--) solve();
66+
67+
#ifdef LOCAL
68+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
69+
#endif
70+
return 0;
71+
}

Codeforces Gym/105789F.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* @file 105789F.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-03-20
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
#define maxn 200005
20+
21+
class SegmentTree {
22+
private:
23+
struct Node {
24+
Node *l, *r;
25+
multiset<int> S;
26+
int ans;
27+
Node(void) { l = r = nullptr, ans = 0; }
28+
};
29+
30+
Node *root;
31+
int n;
32+
33+
void pushUp(Node *p) {
34+
return p->ans = max(p->S.empty() ? 0 : *p->S.rbegin(), min((p->l ? p->l->ans : 0), (p->r ? p->r->ans : 0))), void();
35+
}
36+
37+
void insert(Node *&p, int l, int r, int ql, int qr, int v) {
38+
if (!p) p = new Node();
39+
if (ql <= l && r <= qr) return p->S.insert(v), pushUp(p);
40+
int mid = (l + r) >> 1;
41+
if (ql <= mid) insert(p->l, l, mid, ql, qr, v);
42+
if (qr > mid) insert(p->r, mid + 1, r, ql, qr, v);
43+
return pushUp(p);
44+
}
45+
void erase(Node *&p, int l, int r, int ql, int qr, int v) {
46+
if (ql <= l && r <= qr) return p->S.erase(p->S.find(v)), pushUp(p);
47+
int mid = (l + r) >> 1;
48+
if (ql <= mid) erase(p->l, l, mid, ql, qr, v);
49+
if (qr > mid) erase(p->r, mid + 1, r, ql, qr, v);
50+
return pushUp(p);
51+
}
52+
int query(Node *p, int l, int r, int ql, int qr) {
53+
if (!p) return 0;
54+
if (ql <= l && r <= qr) return p->ans;
55+
int mid = (l + r) >> 1, ans = INT_MAX;
56+
if (ql <= mid) ans = min(ans, query(p->l, l, mid, ql, qr));
57+
if (qr > mid) ans = min(ans, query(p->r, mid + 1, r, ql, qr));
58+
return max(ans, (p->S.empty() ? 0 : *p->S.rbegin()));
59+
}
60+
61+
public:
62+
SegmentTree(void) { root = nullptr, n = 1e9; }
63+
void insert(int l, int r, int v) { return insert(root, 1, n, l, r, v); }
64+
void erase(int l, int r, int v) { return erase(root, 1, n, l, r, v); }
65+
int query(int l, int r) { return query(root, 1, n, l, r); }
66+
} SGT;
67+
68+
int cl[maxn], cr[maxn], cx[maxn];
69+
70+
void solve(void) {
71+
int n, index = 0;
72+
cin >> n;
73+
while (n--) {
74+
char op;
75+
cin >> op;
76+
if (op == '+') {
77+
int l, r, x;
78+
cin >> l >> r >> x, index++, cl[index] = l, cr[index] = r, cx[index] = x;
79+
SGT.insert(l, r - 1, x);
80+
} else if (op == '-') {
81+
int i;
82+
cin >> i;
83+
SGT.erase(cl[i], cr[i] - 1, cx[i]);
84+
} else {
85+
int l, r;
86+
cin >> l >> r;
87+
cout << SGT.query(l, r - 1) << endl;
88+
}
89+
}
90+
return;
91+
}
92+
93+
bool mem2;
94+
95+
int main() {
96+
ios::sync_with_stdio(false), cin.tie(nullptr);
97+
#ifdef LOCAL
98+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
99+
#endif
100+
101+
int _ = 1;
102+
while (_--) solve();
103+
104+
#ifdef LOCAL
105+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
106+
#endif
107+
return 0;
108+
}

Codeforces Gym/105789G.cpp

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* @file 105789G.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-03-20
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
using pll = pair<int64_t, int64_t>;
20+
21+
class SegmentTree {
22+
private:
23+
struct Node {
24+
Node *l, *r;
25+
int64_t minv, maxv, laz;
26+
Node(void) { l = r = nullptr, minv = maxv = 0, laz = -1; }
27+
};
28+
29+
Node *root;
30+
int64_t n;
31+
32+
pll merge(const pll &a, const pll &b) { return {min(a.first, b.first), max(a.second, b.second)}; }
33+
34+
void pushDown(Node *p) {
35+
if (!p->l) p->l = new Node();
36+
if (!p->r) p->r = new Node();
37+
if (p->laz == -1) return;
38+
p->l->minv = p->l->maxv = p->l->laz = p->laz;
39+
p->r->minv = p->r->maxv = p->r->laz = p->laz;
40+
p->laz = -1;
41+
return;
42+
}
43+
void pushUp(Node *p) {
44+
p->minv = INT64_MAX, p->maxv = INT64_MIN;
45+
if (p->l) p->minv = min(p->minv, p->l->minv), p->maxv = max(p->maxv, p->l->maxv);
46+
if (p->r) p->minv = min(p->minv, p->r->minv), p->maxv = max(p->maxv, p->r->maxv);
47+
return;
48+
}
49+
void update(Node *&p, int64_t l, int64_t r, int64_t ql, int64_t qr, int64_t v) {
50+
if (!p) p = new Node();
51+
if (ql <= l && r <= qr) return p->minv = p->maxv = p->laz = v, void();
52+
pushDown(p);
53+
int64_t mid = (l + r) >> 1;
54+
if (ql <= mid) update(p->l, l, mid, ql, qr, v);
55+
if (qr > mid) update(p->r, mid + 1, r, ql, qr, v);
56+
return pushUp(p);
57+
}
58+
pll query(Node *p, int64_t l, int64_t r, int64_t ql, int64_t qr) {
59+
if (!p) return {0, 0};
60+
if (ql <= l && r <= qr) return {p->minv, p->maxv};
61+
pushDown(p);
62+
int64_t mid = (l + r) >> 1;
63+
if (qr <= mid) return query(p->l, l, mid, ql, qr);
64+
if (ql > mid) return query(p->r, mid + 1, r, ql, qr);
65+
return merge(query(p->l, l, mid, ql, qr), query(p->r, mid + 1, r, ql, qr));
66+
}
67+
68+
public:
69+
SegmentTree(void) { root = nullptr, n = 1e18 + 1e9 + 5; }
70+
void update(int64_t l, int64_t r, int64_t v) { return update(root, 1, n, l, r, v); }
71+
pll query(int64_t l, int64_t r) { return query(root, 1, n, l, r); }
72+
} SGT;
73+
74+
void solve(void) {
75+
int n;
76+
cin >> n;
77+
while (n--) {
78+
char op;
79+
int64_t len, pos;
80+
cin >> op >> len >> pos;
81+
if (op == '|') {
82+
int64_t low = SGT.query(pos, pos).first;
83+
SGT.update(pos, pos, low + len);
84+
cout << 'S';
85+
} else {
86+
auto [low, high] = SGT.query(pos, pos + len - 1);
87+
if (low != high)
88+
cout << 'U';
89+
else
90+
cout << 'S', SGT.update(pos, pos + len - 1, low + 1);
91+
}
92+
}
93+
cout << endl;
94+
return;
95+
}
96+
97+
bool mem2;
98+
99+
int main() {
100+
ios::sync_with_stdio(false), cin.tie(nullptr);
101+
#ifdef LOCAL
102+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
103+
#endif
104+
105+
int _ = 1;
106+
while (_--) solve();
107+
108+
#ifdef LOCAL
109+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
110+
#endif
111+
return 0;
112+
}

Codeforces Gym/105789I.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* @file 105789I.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-03-20
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
#define maxn 1000005
20+
21+
int a[maxn], lef[maxn], rig[maxn];
22+
bool avai[maxn];
23+
24+
void solve(void) {
25+
int n;
26+
cin >> n;
27+
for (int i = 0; i < n; i++) cin >> a[i], avai[a[i]] = true;
28+
for (int i = 0; i < n; i++) rig[a[i]] = a[(i + 1) % n], lef[a[(i + 1) % n]] = a[i];
29+
int q;
30+
cin >> q;
31+
while (q--) {
32+
char op;
33+
cin >> op;
34+
if (op == '-') {
35+
int x;
36+
cin >> x;
37+
avai[x] = false;
38+
rig[lef[x]] = rig[x], lef[rig[x]] = lef[x];
39+
} else if (op == '+') {
40+
int x, p;
41+
cin >> x >> p;
42+
avai[x] = true;
43+
lef[x] = lef[p], rig[x] = p;
44+
rig[lef[x]] = lef[rig[x]] = x;
45+
} else {
46+
int len;
47+
cin >> len;
48+
vector<int> a(2 * len);
49+
for (int i = 0; i < len; i++) cin >> a[i], a[i + len] = a[i];
50+
int ans = 0;
51+
for (int l = 0, r; l < 2 * len; l = r + 1) {
52+
r = l;
53+
if (!avai[a[l]]) continue;
54+
while (r + 1 < 2 * len && avai[a[r + 1]] && rig[a[r]] == a[r + 1]) r++;
55+
ans = max(ans, r - l + 1);
56+
}
57+
if (ans > len)
58+
cout << '*' << endl;
59+
else
60+
cout << ans << endl;
61+
}
62+
}
63+
return;
64+
}
65+
66+
bool mem2;
67+
68+
int main() {
69+
ios::sync_with_stdio(false), cin.tie(nullptr);
70+
#ifdef LOCAL
71+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
72+
#endif
73+
74+
int _ = 1;
75+
while (_--) solve();
76+
77+
#ifdef LOCAL
78+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
79+
#endif
80+
return 0;
81+
}

0 commit comments

Comments
 (0)