-
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.
- Loading branch information
Showing
5 changed files
with
404 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
Misc/Tsinghua University Bootcamp in Summer 2024/Tsinghua Bootcamp 2024. Day 1/A.cpp
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,97 @@ | ||
/** | ||
* @file A.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-08-20 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#ifndef LOCAL | ||
#define endl '\n' | ||
#endif | ||
|
||
bool mem1; | ||
|
||
#define maxn 1000005 | ||
|
||
int64_t a[maxn], cnt[2][10]; | ||
|
||
bool chk(int m1, int m2, int64_t cnt[]) { | ||
if (m1 < cnt[1]) return false; | ||
m1 -= cnt[1]; | ||
if (m2 <= cnt[2]) return 2 * (cnt[2] - m2) + cnt[4] <= m1; | ||
m2 -= cnt[2]; | ||
if (m2 <= 2 * cnt[4]) return cnt[4] - m2 / 2 + (m2 % 2) <= m1; | ||
m2 -= cnt[4] * 2; | ||
if (m2 <= 3 * cnt[6]) return m2 % 3 <= m1; | ||
m2 -= cnt[6] * 3; | ||
if (m2 <= cnt[3]) return m2 <= m1; | ||
return false; | ||
} | ||
|
||
void solve(void) { | ||
int m, k; | ||
cin >> m >> k; | ||
for (int i = 1; i <= m; i++) cin >> a[i]; | ||
int n = m >> 1; | ||
for (int i = 1; i <= n; i++) a[i] -= a[m - i + 1]; | ||
a[n + 1] = a[0] = 0; | ||
for (int i = n + 1; i; i--) a[i] -= a[i - 1]; | ||
n++; | ||
if (k == 1) { | ||
int64_t ans = 0; | ||
for (int i = 1; i <= n; i++) | ||
if (a[i] > 0) ans += a[i]; | ||
cout << ans << endl; | ||
return; | ||
} else if (k == 2) { | ||
int64_t sum = 0, cnt[2] = {0, 0}; | ||
for (int i = 1; i <= n; i++) | ||
if (a[i] > 0) | ||
sum += a[i], cnt[0] += a[i] / 2; | ||
else | ||
cnt[1] += -a[i] / 2; | ||
cout << sum - min(cnt[0], cnt[1]) << endl; | ||
return; | ||
} | ||
for (int i = 1; i <= n; i++) { | ||
if (!a[i]) continue; | ||
int t = a[i] > 0; | ||
a[i] = abs(a[i]); | ||
cnt[t][6] += (a[i] - 2) / 6, a[i] = (a[i] - 2) % 6 + 2; | ||
if (a[i] == 5 || a[i] == 7) cnt[t][3]++, a[i] -= 3; | ||
cnt[t][a[i]]++; | ||
} | ||
int64_t tot = 0, ans = INT64_MAX; | ||
for (int i = 1; i <= 6; i++) tot += i * cnt[0][i]; | ||
for (int m1 = cnt[0][1] + 2 * cnt[0][2] + 3 * cnt[0][3] + 4 * cnt[0][4] + 6; ~m1; m1--) | ||
for (int m2 = cnt[0][2] + cnt[0][3] + 2 * cnt[0][4] + 3; ~m2; m2--) { | ||
if (m1 + m2 * 2 > tot || (tot - m1 - m2 * 2) % 3) continue; | ||
int64_t m3 = (tot - m1 - m2 * 2) / 3; | ||
if (m1 + m2 + m3 >= ans) continue; | ||
if (chk(m1, m2, cnt[0]) && chk(m1, m2, cnt[1])) ans = m1 + m2 + m3; | ||
} | ||
cout << ans << endl; | ||
return; | ||
} | ||
|
||
bool mem2; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr); | ||
#ifdef LOCAL | ||
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; | ||
#endif | ||
|
||
int _ = 1; | ||
while (_--) solve(); | ||
|
||
#ifdef LOCAL | ||
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; | ||
#endif | ||
return 0; | ||
} |
144 changes: 144 additions & 0 deletions
144
Misc/Tsinghua University Bootcamp in Summer 2024/Tsinghua Bootcamp 2024. Day 2/J.cpp
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,144 @@ | ||
/** | ||
* @file J.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-08-21 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define maxn 100005 | ||
|
||
class SegmentTree { | ||
private: | ||
int64_t minv[maxn << 2], maxv[maxn << 2], sum[maxn << 2], laz[maxn << 2]; | ||
int n; | ||
|
||
void pushDown(int p, int l, int r) { | ||
if (!laz[p]) return; | ||
int mid = (l + r) >> 1; | ||
sum[p << 1] += (mid - l + 1) * laz[p], minv[p << 1] += laz[p], maxv[p << 1] += laz[p], laz[p << 1] += laz[p]; | ||
sum[p << 1 | 1] += (r - mid) * laz[p], minv[p << 1 | 1] += laz[p], maxv[p << 1 | 1] += laz[p], | ||
laz[p << 1 | 1] += laz[p]; | ||
laz[p] = 0; | ||
return; | ||
} | ||
void pushUp(int p) { | ||
minv[p] = min(minv[p << 1], minv[p << 1 | 1]), maxv[p] = max(maxv[p << 1], maxv[p << 1 | 1]); | ||
sum[p] = sum[p << 1] + sum[p << 1 | 1]; | ||
return; | ||
} | ||
void build(int p, int l, int r, int a[]) { | ||
if (l == r) return minv[p] = maxv[p] = sum[p] = a[l], void(); | ||
int mid = (l + r) >> 1; | ||
build(p << 1, l, mid, a), build(p << 1 | 1, mid + 1, r, a); | ||
return pushUp(p); | ||
} | ||
void add(int p, int l, int r, int ql, int qr, int64_t v) { | ||
if (ql <= l && r <= qr) return minv[p] += v, maxv[p] += v, laz[p] += v, sum[p] += (r - l + 1) * v, void(); | ||
pushDown(p, l, r); | ||
int mid = (l + r) >> 1; | ||
if (ql <= mid) add(p << 1, l, mid, ql, qr, v); | ||
if (qr > mid) add(p << 1 | 1, mid + 1, r, ql, qr, v); | ||
return pushUp(p); | ||
} | ||
void div(int p, int l, int r, int ql, int qr, int64_t v) { | ||
if (ql <= l && r <= qr && minv[p] == maxv[p]) { | ||
int64_t d = minv[p] / v, val = (minv[p] > 0) ? d : (d - (v * d != minv[p])); | ||
laz[p] += val - minv[p], sum[p] += (r - l + 1) * (val - minv[p]), minv[p] = maxv[p] = val; | ||
return; | ||
} | ||
if (ql <= l && r <= qr && minv[p] + 1 == maxv[p]) { | ||
int64_t d = minv[p] / v, val = (minv[p] > 0) ? d : (d - (v * d != minv[p])); | ||
int64_t _d = maxv[p] / v, _val = (maxv[p] > 0) ? _d : (_d - (v * _d != maxv[p])); | ||
if (minv[p] - val == maxv[p] - _val) { | ||
laz[p] += val - minv[p], sum[p] += (r - l + 1) * (val - minv[p]); | ||
minv[p] = val; | ||
maxv[p] = _val; | ||
return; | ||
} | ||
} | ||
pushDown(p, l, r); | ||
int mid = (l + r) >> 1; | ||
if (ql <= mid) div(p << 1, l, mid, ql, qr, v); | ||
if (qr > mid) div(p << 1 | 1, mid + 1, r, ql, qr, v); | ||
return pushUp(p); | ||
} | ||
int64_t getMin(int p, int l, int r, int ql, int qr) { | ||
if (ql <= l && r <= qr) return minv[p]; | ||
pushDown(p, l, r); | ||
int mid = (l + r) >> 1; | ||
if (qr <= mid) return getMin(p << 1, l, mid, ql, qr); | ||
if (ql > mid) return getMin(p << 1 | 1, mid + 1, r, ql, qr); | ||
return min(getMin(p << 1, l, mid, ql, qr), getMin(p << 1 | 1, mid + 1, r, ql, qr)); | ||
} | ||
int64_t getSum(int p, int l, int r, int ql, int qr) { | ||
if (ql <= l && r <= qr) return sum[p]; | ||
pushDown(p, l, r); | ||
int mid = (l + r) >> 1; | ||
if (qr <= mid) return getSum(p << 1, l, mid, ql, qr); | ||
if (ql > mid) return getSum(p << 1 | 1, mid + 1, r, ql, qr); | ||
return getSum(p << 1, l, mid, ql, qr) + getSum(p << 1 | 1, mid + 1, r, ql, qr); | ||
} | ||
void print(int p, int l, int r) { | ||
if (l == r) { | ||
cerr << l << ' ' << r << ' ' << sum[p] << ' ' << minv[p] << ' ' << maxv[p] << endl; | ||
return; | ||
} | ||
pushDown(p, l, r); | ||
int mid = (l + r) >> 1; | ||
print(p << 1, l, mid), print(p << 1 | 1, mid + 1, r); | ||
return pushUp(p); | ||
} | ||
|
||
public: | ||
void resize(int _n) { return n = _n, void(); } | ||
void build(int a[]) { return build(1, 1, n, a); } | ||
void add(int l, int r, int64_t v) { return add(1, 1, n, l, r, v); } | ||
void div(int l, int r, int64_t v) { return div(1, 1, n, l, r, v); } | ||
int64_t getMin(int l, int r) { return getMin(1, 1, n, l, r); } | ||
int64_t getSum(int l, int r) { return getSum(1, 1, n, l, r); } | ||
void print(void) { return print(1, 1, n); } | ||
} ST; | ||
|
||
int read(void) { | ||
char c = getchar(); | ||
int64_t f = +1, x = 0; | ||
while (c < '0' || c > '9') (c == '-') && (f = -f), c = getchar(); | ||
while ('0' <= c && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); | ||
return x * f; | ||
} | ||
|
||
int a[maxn]; | ||
|
||
void solve(void) { | ||
int n = read(), q = read(); | ||
ST.resize(n); | ||
for (int i = 1; i <= n; i++) a[i] = read(); | ||
ST.build(a); | ||
while (q--) { | ||
int op = read(), l = read(), r = read(); | ||
if (op == 1) | ||
ST.add(l, r, read()); | ||
else if (op == 2) | ||
ST.div(l, r, read()); | ||
else if (op == 3) | ||
cout << ST.getMin(l, r) << endl; | ||
else | ||
cout << ST.getSum(l, r) << endl; | ||
} | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int _ = 1; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
57 changes: 57 additions & 0 deletions
57
Misc/Tsinghua University Bootcamp in Summer 2024/Tsinghua Bootcamp 2024. Day 3/B.cpp
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,57 @@ | ||
/** | ||
* @file B.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-08-22 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define maxn 5005 | ||
#define mod 1000000007 | ||
|
||
bool mem1; | ||
|
||
int cnt[maxn]; | ||
int f[3][maxn][maxn]; | ||
|
||
int64_t Mod(int64_t x) { return x >= mod ? x - mod : x; } | ||
|
||
bool mem2; | ||
|
||
void solve(void) { | ||
int n, m; | ||
cin >> n >> m; | ||
for (int i = 1, x; i <= n; i++) cin >> x, cnt[x]++; | ||
f[1][0][0] = 1; | ||
for (int i = 1; i <= m; i++) { | ||
int p = i % 3, q = (i + 1) % 3; | ||
for (int j = 0; j <= cnt[i + 1]; j++) | ||
for (int k = 0; k <= cnt[i + 2]; k++) f[q][j][k] = 0; | ||
for (int j = 0; j <= cnt[i]; j++) | ||
for (int k = 0; k <= cnt[i + 1]; k++) | ||
if (f[p][j][k]) { | ||
int vl = (cnt[i] - j) % 3, vr = min({cnt[i] - j, cnt[i + 1] - k, cnt[i + 2]}); | ||
while ((cnt[i] - j - vr) % 3) vr--; | ||
if (vl > vr) continue; | ||
f[q][k + vl][vl] = Mod(f[q][k + vl][vl] + f[p][j][k]); | ||
f[q][k + vr + 3][vr + 3] = Mod(f[q][k + vr + 1][vr + 1] + mod - f[p][j][k]); | ||
} | ||
for (int j = 0; j <= cnt[i + 1]; j++) | ||
for (int k = 0; k <= cnt[i + 2]; k++) f[q][j + 3][k + 3] = Mod(f[q][j + 3][k + 3] + f[q][j][k]); | ||
} | ||
cout << f[(m + 1) % 3][0][0] << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int _ = 1; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
43 changes: 43 additions & 0 deletions
43
Misc/Tsinghua University Bootcamp in Summer 2024/Tsinghua Bootcamp 2024. Day 3/D.cpp
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,43 @@ | ||
/** | ||
* @file D.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-08-22 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
bool mem1; | ||
|
||
#define maxn 100005 | ||
|
||
int64_t l[maxn], r[maxn]; | ||
|
||
bool mem2; | ||
|
||
void solve(void) { | ||
int n; | ||
int64_t sum, suml = 0, sumr = 0; | ||
cin >> n >> sum; | ||
for (int i = 1; i <= n; i++) cin >> l[i] >> r[i], suml += l[i], sumr += r[i]; | ||
for (int i = 1; i <= n; i++) { | ||
suml -= l[i], sumr -= r[i]; | ||
int64_t vl = max(l[i], sum - sumr), vr = min(r[i], sum - suml); | ||
cout << max((int64_t)0, vr - vl + 1) << ' '; | ||
suml += l[i], sumr += r[i]; | ||
} | ||
cout << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int _ = 1; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.