Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 12668d2

Browse files
committed
灵茶の试炼 * 7 (无UT) & algo-hub-cpp & clean code
1 parent 2d991cc commit 12668d2

32 files changed

+2374
-302
lines changed

‎algo-hub-cpp/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required(VERSION 3.31)
2+
project(algo_hub_cpp)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
6+
add_executable(P1144 最短路计数 "luogu/P1144 最短路计数.cpp")
7+
add_executable(P1725 琪露诺 "luogu/P1725 琪露诺.cpp")
8+
add_executable(P1966 [NOIP 2013 提高组] 火柴排队 "luogu/P1966 [NOIP 2013 提高组] 火柴排队.cpp")
9+
add_executable(P1972 [SDOI2009] HH的项链 "luogu/P1972 [SDOI2009] HH的项链.cpp")
10+
add_executable(P3373 【模板】线段树 2 "luogu/P3373 【模板】线段树 2.cpp")
11+
add_executable(P3376 【模板】网络最大流 "luogu/P3376 【模板】网络最大流.cpp")
12+
add_executable(P3381 【模板】最小费用最大流 "luogu/P3381 【模板】最小费用最大流.cpp")
13+
add_executable(P3594 [POI2015] WIL "luogu/P3594 [POI2015] WIL.cpp")
14+
add_executable(P3901 数列找不同 "luogu/P3901 数列找不同.cpp")
15+
add_executable(P4513 小白逛公园 "luogu/P4513 小白逛公园.cpp")
16+
add_executable(P5490 【模板】扫描线 & 矩形面积并 "luogu/P5490 【模板】扫描线 & 矩形面积并.cpp")

‎luogu/src/main/java/P1144 最短路计数.cpp renamed to ‎algo-hub-cpp/luogu/P1144 最短路计数.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ typedef long long ll;
55

66
const int mod = 100003;
77
int n, m;
8-
vector<vector<int>> g;
8+
vector<vector<int>> g;
99

1010
void solve() {
1111
cin >> n >> m;
@@ -50,12 +50,11 @@ signed main() {
5050
cin.tie(nullptr);
5151

5252
int t = 1;
53-
// cin >> t;
54-
while (t--) {
55-
solve();
56-
}
53+
// cin >> t;
54+
while (t--) solve();
5755
return 0;
5856
}
57+
5958
/*
6059
https://www.luogu.com.cn/problem/P1144
61-
*/
60+
*/

‎algo-hub-cpp/luogu/P1725 琪露诺.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
6+
void solve() {
7+
int n, l, r;
8+
cin >> n >> l >> r;
9+
10+
vector<int> a(n + 1);
11+
for (int i = 0; i < n + 1; ++i) {
12+
cin >> a[i];
13+
}
14+
15+
vector<ll> f(n + 1);
16+
for (int i = 1; i < l; i++) {
17+
f[i] = -1e18;
18+
}
19+
deque<int> dq;
20+
for (int i = l; i <= n; i++) {
21+
while (!dq.empty() && f[i - l] >= f[dq.back()]) {
22+
dq.pop_back();
23+
}
24+
dq.push_back(i - l);
25+
if (dq.front() < i - r) {
26+
dq.pop_front();
27+
}
28+
f[i] = f[dq.front()] + a[i];
29+
}
30+
ll ans = f[n - r + 1];
31+
for (int i = n - r + 1; i < f.size(); i++) {
32+
ans = max(ans, f[i]);
33+
}
34+
cout << ans << endl;
35+
}
36+
37+
signed main() {
38+
ios::sync_with_stdio(false);
39+
cin.tie(nullptr);
40+
41+
int t = 1;
42+
// cin >> t;
43+
while (t--) solve();
44+
return 0;
45+
}
46+
47+
/*
48+
https://www.luogu.com.cn/problem/P1725
49+
*/
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
6+
int n;
7+
8+
vector<int> f(vector<int> &a) {
9+
int m = 0;
10+
map<int, int> mp;
11+
for (const auto &v: a) mp[v] = 1;
12+
for (auto &p: mp) p.second = m++;
13+
vector<int> A(m);
14+
// for (auto &p: mp) A[p.second] = p.first;
15+
for (int i = 0; i < n; ++i) A[i] = mp[a[i]];
16+
return A;
17+
}
18+
19+
ll mergeCount(vector<int> &a) {
20+
int n = a.size();
21+
if (n <= 1) {
22+
return 0;
23+
}
24+
vector<int> left = vector(a.begin(), a.begin() + n / 2);
25+
vector<int> right = vector(a.begin() + n / 2, a.end());
26+
ll cnt = mergeCount(left) + mergeCount(right);
27+
int l = 0, r = 0;
28+
for (int i = 0; i < n; i++) {
29+
if (l < left.size() && (r == right.size() || left[l] <= right[r])) {
30+
a[i] = left[l];
31+
l++;
32+
} else {
33+
cnt += n / 2 - l;
34+
a[i] = right[r];
35+
r++;
36+
}
37+
}
38+
return cnt;
39+
}
40+
41+
void solve() {
42+
cin >> n;
43+
vector<int> a(n), b(n);
44+
for (int i = 0; i < n; ++i) cin >> a[i];
45+
for (int i = 0; i < n; ++i) cin >> b[i];
46+
47+
a = f(a);
48+
vector<int> p(n);
49+
for (int i = 0; i < n; ++i) p[a[i]] = i;
50+
b = f(b);
51+
for (int i = 0; i < n; ++i) b[i] = p[b[i]];
52+
53+
int mod = 1e8 - 3;
54+
ll ans = mergeCount(b) % mod;
55+
cout << ans << endl;
56+
}
57+
58+
signed main() {
59+
ios::sync_with_stdio(false);
60+
cin.tie(nullptr);
61+
62+
int t = 1;
63+
// cin >> t;
64+
while (t--) solve();
65+
return 0;
66+
}
67+
68+
/*
69+
https://www.luogu.com.cn/problem/P1966
70+
*/

‎luogu/src/main/java/P1972 [SDOI2009] HH的项链.cpp renamed to ‎algo-hub-cpp/luogu/P1972 [SDOI2009] HH的项链.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ vector<int> a;
99
struct QUE {
1010
int l, r, i;
1111
};
12+
1213
vector<QUE> qs;
1314

1415
struct BIT {
@@ -80,12 +81,11 @@ signed main() {
8081
cin.tie(nullptr);
8182

8283
int t = 1;
83-
// cin >> t;
84-
while (t--) {
85-
solve();
86-
}
84+
// cin >> t;
85+
while (t--) solve();
8786
return 0;
8887
}
88+
8989
/*
9090
https://www.luogu.com.cn/problem/P1972
91-
*/
91+
*/
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
6+
int mod;
7+
8+
template<class Info, class Tag>
9+
struct LazySegmentTree {
10+
const int n;
11+
vector<Info> info;
12+
vector<Tag> tag;
13+
14+
LazySegmentTree(int n) : n(n), info(4 << (int) log2(n)), tag(4 << (int) log2(n)) {
15+
}
16+
17+
LazySegmentTree(vector<Info> init) : LazySegmentTree(init.size()) {
18+
function<void(int, int, int)> build = [&](int p, int l, int r) {
19+
if (l == r) {
20+
info[p] = init[l - 1];
21+
return;
22+
}
23+
int m = (l + r) / 2;
24+
build(2 * p, l, m);
25+
build(2 * p + 1, m + 1, r);
26+
pull(p);
27+
};
28+
build(1, 1, n);
29+
}
30+
31+
void pull(int p) {
32+
info[p] = info[p * 2] + info[p * 2 + 1];
33+
}
34+
35+
void apply(int p, int l, int r, const Tag &v) {
36+
info[p].apply(l, r, v);
37+
tag[p].apply(v);
38+
}
39+
40+
void push(int p, int l, int r) {
41+
int m = (l + r) / 2;
42+
apply(2 * p, l, m, tag[p]);
43+
apply(2 * p + 1, m + 1, r, tag[p]);
44+
tag[p] = Tag();
45+
}
46+
47+
Info rangeQuery(int p, int l, int r, int ql, int qr) {
48+
if (ql <= l && r <= qr) {
49+
return info[p];
50+
}
51+
int m = (l + r) / 2;
52+
push(p, l, r);
53+
if (qr <= m) return rangeQuery(2 * p, l, m, ql, qr);
54+
if (ql > m) return rangeQuery(2 * p + 1, m + 1, r, ql, qr);
55+
return rangeQuery(2 * p, l, m, ql, qr) +
56+
rangeQuery(2 * p + 1, m + 1, r, ql, qr);
57+
}
58+
59+
// 查询区间 [l,r)
60+
Info rangeQuery(int l, int r) {
61+
return rangeQuery(1, 1, n, l, r);
62+
}
63+
64+
void rangeApply(int p, int l, int r, int ql, int qr, const Tag &v) {
65+
if (ql <= l && r <= qr) {
66+
apply(p, l, r, v);
67+
return;
68+
}
69+
int m = (l + r) / 2;
70+
push(p, l, r);
71+
if (ql <= m) rangeApply(2 * p, l, m, ql, qr, v);
72+
if (qr > m) rangeApply(2 * p + 1, m + 1, r, ql, qr, v);
73+
pull(p);
74+
}
75+
76+
void rangeApply(int l, int r, const Tag &v) {
77+
rangeApply(1, 1, n, l, r, v);
78+
}
79+
};
80+
81+
struct Tag {
82+
ll add;
83+
ll mul;
84+
85+
Tag(int _add = 0, int _mul = 1) : add{_add}, mul{_mul} {
86+
}
87+
88+
void apply(const Tag &t) {
89+
if (t.mul != 1) {
90+
mul = (mul * t.mul) % mod;
91+
add = (add * t.mul) % mod;
92+
}
93+
if (t.add != 0) {
94+
add = (add + t.add) % mod;
95+
}
96+
}
97+
};
98+
99+
struct Info {
100+
ll sm = 0;
101+
102+
void apply(int l, int r, const Tag &t) {
103+
ll sz = r - l + 1;
104+
// 先乘后加
105+
if (t.mul != 1) {
106+
sm = (sm * t.mul) % mod;
107+
}
108+
if (t.add != 0) {
109+
sm = (sm + sz * t.add) % mod;
110+
}
111+
}
112+
};
113+
114+
Info operator+(Info a, Info b) {
115+
Info c;
116+
c.sm = (a.sm + b.sm) % mod;
117+
return c;
118+
}
119+
120+
void solve() {
121+
int n, q;
122+
cin >> n >> q >> mod;
123+
124+
// vector<int> a(n);
125+
vector<Info> init(n);
126+
for (int i = 0; i < n; ++i) {
127+
cin >> init[i].sm;
128+
}
129+
130+
LazySegmentTree<Info, Tag> seg(init);
131+
for (int i = 0; i < q; ++i) {
132+
int op, x, y, k;
133+
cin >> op >> x >> y;
134+
135+
if (op == 1) {
136+
cin >> k;
137+
seg.rangeApply(x, y, {0, k});
138+
} else if (op == 2) {
139+
cin >> k;
140+
seg.rangeApply(x, y, {k, 1});
141+
} else {
142+
cout << seg.rangeQuery(x, y).sm << endl;
143+
}
144+
}
145+
}
146+
147+
signed main() {
148+
ios::sync_with_stdio(false);
149+
cin.tie(nullptr);
150+
151+
int t = 1;
152+
// cin >> t;
153+
while (t--) solve();
154+
return 0;
155+
}
156+
157+
/*
158+
https://www.luogu.com.cn/problem/P3373
159+
*/

‎luogu/src/main/java/P3376 【模板】网络最大流.cpp renamed to ‎algo-hub-cpp/luogu/P3376 【模板】网络最大流.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ void add(int x, int y, int z) {
1414
ver[++tot] = x, edge[tot] = 0, Next[tot] = head[y], head[y] = tot;
1515
}
1616

17-
bool bfs() { // 在残量网络上构造分层图
17+
bool bfs() {
18+
// 在残量网络上构造分层图
1819
memset(d, 0, sizeof(d));
1920
while (!q.empty()) q.pop();
2021
q.push(s);
@@ -33,7 +34,8 @@ bool bfs() { // 在残量网络上构造分层图
3334
return false;
3435
}
3536

36-
int dinic(int x, int flow) { // 在当前分层图上增广
37+
int dinic(int x, int flow) {
38+
// 在当前分层图上增广
3739
if (x == t) return flow;
3840
int rest = flow, k;
3941
for (int i = head[x]; i && rest; i = Next[i]) {
@@ -64,6 +66,7 @@ signed main() {
6466
cout << maxflow << endl;
6567
return 0;
6668
}
69+
6770
/*
6871
https://www.luogu.com.cn/problem/P3376
69-
*/
72+
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /