Skip to content

Commit 4b9d7fa

Browse files
committed
CCPC Online 2025
1 parent 3c0f9df commit 4b9d7fa

File tree

4 files changed

+253
-0
lines changed

4 files changed

+253
-0
lines changed

QOJ/14547.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @file 14547.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-09-06
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#define endl '\n'
14+
15+
void solve(void) {
16+
int n, m;
17+
cin >> n >> m;
18+
vector<vector<int>> a(n + 2, vector<int>(m + 2, 0));
19+
20+
auto add = [&](int xl, int xr, int yl, int yr) -> void {
21+
a[xl][yl]++;
22+
a[xl][yr + 1]--;
23+
a[xr + 1][yl]--;
24+
a[xr + 1][yr + 1]++;
25+
return;
26+
};
27+
28+
for (int x = 0; x <= min(n, m); x++)
29+
for (int y = 1; x + y <= min(n, m); y++) {
30+
add(0, n - x - y, x, m - y);
31+
add(y, n - x, 0, m - x - y);
32+
add(x + y, n, y, m - x);
33+
add(x, n - y, x + y, m);
34+
}
35+
36+
for (int i = 0; i <= n; i++)
37+
for (int j = 1; j <= m; j++) a[i][j] += a[i][j - 1];
38+
39+
for (int i = 1; i <= n; i++)
40+
for (int j = 0; j <= m; j++) a[i][j] += a[i - 1][j];
41+
42+
for (int i = 0; i <= n; i++) {
43+
for (int j = 0; j <= m; j++) cout << a[i][j] << ' ';
44+
cout << endl;
45+
}
46+
47+
return;
48+
}
49+
50+
int main() {
51+
ios::sync_with_stdio(false), cin.tie(nullptr);
52+
53+
int _ = 1;
54+
while (_--) solve();
55+
56+
return 0;
57+
}

QOJ/14548.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @file 14548.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-09-06
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#define endl '\n'
14+
15+
#define maxn 100005
16+
17+
struct Block {
18+
int64_t val, cnt;
19+
int top;
20+
21+
bool operator<(const Block& o) const {
22+
if (this->val * o.cnt != o.val * this->cnt) return this->val * o.cnt < o.val * this->cnt;
23+
return this->top < o.top;
24+
}
25+
};
26+
27+
vector<int> graph[maxn];
28+
Block a[maxn];
29+
int fa[maxn], f[maxn];
30+
31+
int getfa(int p) { return f[p] == p ? p : f[p] = getfa(f[p]); }
32+
33+
void dfs(int p, int pre = 0) {
34+
fa[p] = pre;
35+
for (auto q : graph[p])
36+
if (q != pre) dfs(q, p);
37+
return;
38+
}
39+
40+
void solve(void) {
41+
int n, X;
42+
cin >> n >> X;
43+
44+
for (int i = 1, x, y; i < n; i++) cin >> x >> y, graph[x].push_back(y), graph[y].push_back(x);
45+
46+
int64_t ans = 0;
47+
48+
for (int i = 2, op; i <= n; i++) {
49+
cin >> op;
50+
if (op == 1)
51+
a[i] = {0, 1, i};
52+
else {
53+
int64_t x, d, h;
54+
cin >> x >> d >> h;
55+
a[i] = {h / (X - d) + (h % (X - d) > 0) - 1, 0, i};
56+
ans -= a[i].val * x;
57+
}
58+
}
59+
60+
dfs(1);
61+
62+
for (int i = 1; i <= n; i++) f[i] = i;
63+
64+
multiset<Block> S;
65+
66+
a[1] = {0, 0, 1};
67+
for (int i = 2; i <= n; i++)
68+
if (a[i].val > 0 || a[i].cnt > 0) S.insert(a[i]);
69+
70+
while (!S.empty()) {
71+
int p = S.begin()->top, q = getfa(fa[p]);
72+
S.erase(a[p]);
73+
if (q != 1) S.erase(a[q]);
74+
75+
ans += a[q].cnt * a[p].val;
76+
a[q].val += a[p].val;
77+
a[q].cnt += a[p].cnt;
78+
f[p] = q;
79+
80+
if (q != 1) S.insert(a[q]);
81+
}
82+
83+
cout << ans << endl;
84+
85+
return;
86+
}
87+
88+
int main() {
89+
ios::sync_with_stdio(false), cin.tie(nullptr);
90+
91+
int _ = 1;
92+
while (_--) solve();
93+
94+
return 0;
95+
}

QOJ/14551.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @file 14551.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-09-06
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#define endl '\n'
14+
15+
void solve(void) {
16+
int n, m;
17+
cin >> n >> m;
18+
int x = (n + 1) / 2, y = m - x;
19+
cout << 2 * min(x, y) + 1 << endl;
20+
return;
21+
}
22+
23+
int main() {
24+
ios::sync_with_stdio(false), cin.tie(nullptr);
25+
26+
int _ = 1;
27+
cin >> _;
28+
while (_--) solve();
29+
30+
return 0;
31+
}

QOJ/14559.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @file 14559.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-09-06
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#define endl '\n'
14+
15+
using tiii = tuple<int, int, int>;
16+
17+
void printx(const string& s, const vector<tiii>& rec) {
18+
cout << s << ' ' << rec.size() << endl;
19+
for (auto [x, y, z] : rec) cout << x << ' ';
20+
cout << endl;
21+
for (auto [x, y, z] : rec) cout << y << ' ';
22+
cout << endl;
23+
for (auto [x, y, z] : rec) cout << z << ' ';
24+
cout << endl;
25+
return;
26+
}
27+
28+
void makePre(string cmd, int l, int r) {
29+
for (int i = 1; i < 32; i++) {
30+
vector<tiii> rec;
31+
for (int x = l + i; x <= r; x += 32) rec.emplace_back(x - 1, x, x);
32+
printx(cmd, rec);
33+
}
34+
for (int i = l + 32; i <= r; i += 32) {
35+
vector<tiii> rec;
36+
for (int j = i; j < i + 32; j++) rec.emplace_back(i - 1, j, j);
37+
printx(cmd, rec);
38+
}
39+
return;
40+
}
41+
42+
void solve(void) {
43+
cout << 188 << endl;
44+
45+
makePre("add", 0, 1023);
46+
47+
vector<tiii> rec;
48+
for (int i = 0; i < 1024; i++) {
49+
rec.emplace_back(i, i | (1 << 10), i | (1 << 10));
50+
if (rec.size() == 32) printx("mul", rec), rec.clear();
51+
}
52+
53+
makePre("max", 1024, 2047);
54+
55+
for (int i = 0; i < 1024; i++) {
56+
rec.emplace_back(i, i | (1 << 10), i);
57+
if (rec.size() == 32) printx("sub", rec), rec.clear();
58+
}
59+
60+
return;
61+
}
62+
63+
int main() {
64+
ios::sync_with_stdio(false), cin.tie(nullptr);
65+
66+
int _ = 1;
67+
while (_--) solve();
68+
69+
return 0;
70+
}

0 commit comments

Comments
 (0)