Skip to content

Commit 7a1454e

Browse files
committed
QOJ: CCPC FInal
1 parent 2334b07 commit 7a1454e

4 files changed

Lines changed: 286 additions & 49 deletions

File tree

QOJ/11107.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* @file 11107.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-05-13
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+
using pii = pair<int, int>;
22+
23+
map<int, pii> graph[maxn];
24+
multiset<int> near[maxn];
25+
bool ban[maxn];
26+
27+
void solve(void) {
28+
int n, m, k;
29+
cin >> n >> m >> k;
30+
for (int i = 1, x, y, c, t; i <= m; i++)
31+
cin >> x >> y >> c >> t, graph[x][y] = graph[y][x] = {c, t}, near[x].insert(t), near[y].insert(t);
32+
33+
queue<int> que;
34+
for (int i = 1; i <= n; i++)
35+
if (near[i].empty() || *near[i].begin() == *near[i].rbegin()) ban[i] = true, que.push(i);
36+
37+
vector<pii> ans;
38+
while (!que.empty()) {
39+
int p = que.front();
40+
que.pop();
41+
if (near[p].empty()) continue;
42+
ans.emplace_back(p, *near[p].begin());
43+
for (auto [q, w] : graph[p]) {
44+
auto [c, t] = w;
45+
near[p].erase(near[p].find(t)), near[q].erase(near[q].find(t));
46+
graph[q].erase(p);
47+
if (!ban[q] && (near[q].empty() || *near[q].begin() == *near[q].rbegin())) ban[q] = true, que.push(q);
48+
}
49+
graph[p].clear();
50+
}
51+
52+
for (int p = 1; p <= n; p++)
53+
for (auto [q, w] : graph[p])
54+
if (w.first != w.second) return cout << -1 << endl, void();
55+
56+
cout << ans.size() << endl;
57+
reverse(ans.begin(), ans.end());
58+
for (auto [p, t] : ans) cout << p << ' ' << t << endl;
59+
60+
return;
61+
}
62+
63+
bool mem2;
64+
65+
int main() {
66+
ios::sync_with_stdio(false), cin.tie(nullptr);
67+
#ifdef LOCAL
68+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
69+
#endif
70+
71+
int _ = 1;
72+
while (_--) solve();
73+
74+
#ifdef LOCAL
75+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
76+
#endif
77+
return 0;
78+
}

QOJ/11109.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* @file 11109.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-05-13
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 300005
20+
#define maxsqrtn 600
21+
22+
using tiii = tuple<int, int, int>;
23+
24+
vector<tiii> upds[maxn];
25+
int64_t ans[maxsqrtn];
26+
int bel[maxn], ql[maxn], qr[maxn], a[maxn], delt[maxsqrtn], add[maxsqrtn];
27+
deque<int> cnt[maxsqrtn];
28+
29+
void solve(void) {
30+
int n, m;
31+
cin >> n >> m;
32+
for (int i = 1, x1, x2, y1, y2; i <= n; i++) {
33+
cin >> x1 >> x2 >> y1 >> y2;
34+
upds[x1].emplace_back(y1, y2 - 1, +1), upds[x2].emplace_back(y1, y2 - 1, -1);
35+
}
36+
37+
int B = sqrt(n), Bcnt = 0;
38+
while (qr[Bcnt] < n) Bcnt++, ql[Bcnt] = qr[Bcnt - 1] + 1, qr[Bcnt] = min(qr[Bcnt - 1] + B, n);
39+
40+
for (int i = 1; i <= Bcnt; i++) {
41+
cnt[i].push_back(0);
42+
for (int j = ql[i]; j <= qr[i]; j++) cnt[bel[j] = i][a[j] = 0]++;
43+
}
44+
45+
for (int t = 1; t <= n; t++) {
46+
for (auto [l, r, v] : upds[t]) {
47+
if (bel[l] == bel[r]) {
48+
cnt[bel[l]].push_front(0), cnt[bel[l]].push_back(0), delt[bel[l]]--;
49+
for (int i = l; i <= r; i++) cnt[bel[i]][a[i] - delt[bel[l]]]--, a[i] += v, cnt[bel[i]][a[i] - delt[bel[l]]]++;
50+
continue;
51+
}
52+
53+
cnt[bel[l]].push_front(0), cnt[bel[l]].push_back(0), delt[bel[l]]--;
54+
for (int i = l; i <= qr[bel[l]]; i++)
55+
cnt[bel[i]][a[i] - delt[bel[i]]]--, a[i] += v, cnt[bel[i]][a[i] - delt[bel[i]]]++;
56+
57+
for (int t = bel[l] + 1; t < bel[r]; t++) add[t] += v;
58+
59+
cnt[bel[r]].push_front(0), cnt[bel[r]].push_back(0), delt[bel[r]]--;
60+
for (int i = ql[bel[r]]; i <= r; i++)
61+
cnt[bel[i]][a[i] - delt[bel[i]]]--, a[i] += v, cnt[bel[i]][a[i] - delt[bel[i]]]++;
62+
}
63+
for (int b = 1; b <= Bcnt; b++) {
64+
while (cnt[b].front() == 0) cnt[b].pop_front(), delt[b]++;
65+
while (cnt[b].back() == 0) cnt[b].pop_back();
66+
}
67+
68+
for (int b = 1; b <= Bcnt; b++)
69+
for (int v = (delt[b] + add[b] - 1) / m + 1; m * v - delt[b] - add[b] < (int)cnt[b].size(); v++)
70+
ans[v] += cnt[b][m * v - delt[b] - add[b]];
71+
}
72+
73+
for (int i = 1; i <= n / m; i++) cout << ans[i] << endl;
74+
75+
return;
76+
}
77+
78+
bool mem2;
79+
80+
int main() {
81+
ios::sync_with_stdio(false), cin.tie(nullptr);
82+
#ifdef LOCAL
83+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
84+
#endif
85+
86+
int _ = 1;
87+
while (_--) solve();
88+
89+
#ifdef LOCAL
90+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
91+
#endif
92+
return 0;
93+
}

QOJ/11110.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @file 11110.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-05-13
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 5005
20+
#define mod 998244353
21+
22+
int f[maxn][maxn];
23+
24+
int Mod(int x) { return x >= mod ? x - mod : x; }
25+
26+
void solve(void) {
27+
int n, m;
28+
string s, t;
29+
cin >> n >> m >> s >> t;
30+
s = ' ' + s, t = ' ' + t;
31+
32+
auto getT = [&](int i) { return (i <= m || i > n + m) ? '0' : t[i - m]; };
33+
34+
for (int i = 0; i <= n; i++)
35+
for (int j = 0; j <= m; j++) f[i][j] = 0;
36+
37+
f[0][0] = 1;
38+
for (int i = 1; i <= n; i++)
39+
for (int j = 0; j <= m; j++) {
40+
if (!f[i - 1][j]) continue;
41+
if (s[i] != '0' && getT(i + 2 * j) != '0') f[i][j] = Mod(f[i][j] + f[i - 1][j]);
42+
if (s[i] != '0' && j < m && getT(i + 2 * j) != '1' && getT(i + 2 * j + 1) != '1' && getT(i + 2 * j + 2) != '1')
43+
f[i][j + 1] = Mod(f[i][j + 1] + f[i - 1][j]);
44+
if (s[i] != '1' && getT(i + 2 * j) != '1') f[i][j] = Mod(f[i][j] + f[i - 1][j]);
45+
}
46+
47+
cout << f[n][m] << endl;
48+
49+
return;
50+
}
51+
52+
bool mem2;
53+
54+
int main() {
55+
ios::sync_with_stdio(false), cin.tie(nullptr);
56+
#ifdef LOCAL
57+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
58+
#endif
59+
60+
int _ = 1;
61+
cin >> _;
62+
while (_--) solve();
63+
64+
#ifdef LOCAL
65+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
66+
#endif
67+
return 0;
68+
}

QOJ/11112.cpp

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file 11112.cpp
33
* @author Macesuted (i@macesuted.moe)
4-
* @date 2025-05-12
4+
* @date 2025-05-13
55
*
66
* @copyright Copyright (c) 2025
77
*
@@ -10,76 +10,74 @@
1010
#include <bits/stdc++.h>
1111
using namespace std;
1212

13+
#ifndef LOCAL
1314
#define endl '\n'
14-
mt19937_64 rnd(time(nullptr));
15+
#endif
16+
17+
bool mem1;
18+
19+
string gets(string s) {
20+
string ans = s;
21+
for (int i = 1; i < (int)s.size(); i++) s = s.substr(1) + s[0], ans = min(ans, s);
22+
return ans;
23+
}
24+
25+
unordered_set<string> S;
26+
27+
void find(string &s, int n, int rest, int p) {
28+
if (p == n) return S.insert(gets(s)), void();
29+
if (rest > 0) s.push_back('1'), find(s, n, rest - 1, p + 1), s.pop_back();
30+
if (n - p > rest) s.push_back('0'), find(s, n, rest, p + 1), s.pop_back();
31+
return;
32+
}
33+
1534
void solve(void) {
1635
int n, k, m;
1736
cin >> n >> k >> m;
18-
set<string> hap;
37+
1938
string s;
20-
auto dfs = [&](auto self, int p, int num) -> void {
21-
if (p == n) {
22-
hap.insert(s);
23-
return;
24-
}
25-
if (num < k) {
26-
s += '1';
27-
self(self, p + 1, num + 1);
28-
s.pop_back();
29-
}
30-
if (num + (n - p - 1) >= k) {
31-
s += '0';
32-
self(self, p + 1, num);
33-
s.pop_back();
34-
}
35-
};
36-
dfs(dfs, 0, 0);
37-
set<string> hp1, hp2;
38-
auto check = [&](string s) -> bool {
39-
auto iz = s;
40-
sort(iz.begin(), iz.end());
41-
for (int i = 0; i < n; i++) {
42-
if (iz == s) return false;
43-
s = s.substr(1) + s[0];
44-
}
45-
return true;
46-
};
47-
for (auto it : hap) {
48-
if (check(it))
49-
hp1.insert(it);
50-
else
51-
hp2.insert(it);
52-
}
53-
cout << (m * k + n - 1) / n << '\n';
39+
S.clear(), find(s, n, k, 0), S.erase(string(n - k, '0') + string(k, '1'));
40+
41+
cout << (k * m + n - 1) / n << endl;
42+
5443
vector<string> ans;
55-
while (m >= n && !hp1.empty()) {
56-
auto it = *hp1.begin();
57-
while (hp1.count(it)) {
58-
hp1.erase(it);
59-
ans.push_back(it);
60-
m--;
61-
it = it.substr(1) + it[0];
62-
}
44+
while (m > n) {
45+
string o = *S.begin(), s = o;
46+
S.erase(o);
47+
do {
48+
ans.push_back(s), m--, s = s.substr(1) + s[0];
49+
} while (s != o);
6350
}
51+
52+
vector<bool> used(n);
6453
int p = 0;
65-
vector<bool> vis(n, false);
6654
while (m--) {
67-
while (vis[p]) p++;
68-
vis[p] = true;
55+
while (used[p]) p = (p + 1) % n;
56+
used[p] = true;
6957
string s(n, '0');
7058
for (int t = 0; t < k; t++) s[p] = '1', p = (p + 1) % n;
7159
ans.push_back(s);
7260
}
73-
for (auto &s : ans) cout << s << endl;
61+
62+
for (auto s : ans) cout << s << endl;
63+
7464
return;
7565
}
7666

67+
bool mem2;
68+
7769
int main() {
7870
ios::sync_with_stdio(false), cin.tie(nullptr);
71+
#ifdef LOCAL
72+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
73+
#endif
7974

8075
int _ = 1;
8176
cin >> _;
8277
while (_--) solve();
8378

79+
#ifdef LOCAL
80+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
81+
#endif
8482
return 0;
8583
}

0 commit comments

Comments
 (0)