Skip to content

Commit fe7419a

Browse files
committed
add another test for st walk
1 parent 4b1bfab commit fe7419a

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#define PROBLEM \
2+
"https://judge.yosupo.jp/problem/queue_operate_all_composite"
3+
#include "../template.hpp"
4+
#include "../../../library/contest/random.hpp"
5+
#include "../../../library/data_structures_[l,r]/disjoint_rmq.hpp"
6+
#include "../../../library/data_structures_[l,r]/seg_tree.hpp"
7+
const int mod = 998'244'353;
8+
int main() {
9+
cin.tie(0)->sync_with_stdio(0);
10+
int q;
11+
cin >> q;
12+
vector<array<int, 3>> queries(q);
13+
vector<array<int, 2>> init;
14+
for (int i = 0; i < q; i++) {
15+
int type;
16+
cin >> type;
17+
if (type == 0) {
18+
int a, b;
19+
cin >> a >> b;
20+
queries[i] = {type, a, b};
21+
init.push_back({a, b});
22+
} else if (type == 1) {
23+
queries[i] = {type, -1, -1};
24+
} else {
25+
int x;
26+
cin >> x;
27+
queries[i] = {type, x, -1};
28+
}
29+
}
30+
auto f = [&](const array<int, 2>& l,
31+
const array<int, 2>& r) -> array<int, 2> {
32+
return {int(1LL * l[0] * r[0] % mod),
33+
int((1LL * r[0] * l[1] + r[1]) % mod)};
34+
};
35+
tree st(init, f);
36+
disjoint_rmq rmq(init, f);
37+
int l = 0, r = 0; //[l,r)
38+
for (int i = 0; i < q; i++) {
39+
int type = queries[i][0];
40+
if (type == 0) {
41+
r++;
42+
} else if (type == 1) {
43+
l++;
44+
} else {
45+
int x = queries[i][1];
46+
assert(l <= r);
47+
if (l == r) cout << x << '\n';
48+
else {
49+
int which = rnd(0, 2);
50+
st.max_right(l, r - 1,
51+
[&](int m, const array<int, 2>& val) -> bool {
52+
assert(l <= m && m <= r - 1);
53+
assert(val == rmq.query(l, m));
54+
if (which == 0) return 0;
55+
else if (which == 1) return 1;
56+
else return rnd(0, 1);
57+
});
58+
st.min_left(l, r - 1,
59+
[&](int m, const array<int, 2>& val) -> bool {
60+
assert(l <= m && m <= r - 1);
61+
assert(val == rmq.query(m, r - 1));
62+
if (which == 0) return 0;
63+
else if (which == 1) return 1;
64+
else return rnd(0, 1);
65+
});
66+
array<int, 2> line = rmq.query(l, r - 1);
67+
cout << (1LL * line[0] * x + line[1]) % mod
68+
<< '\n';
69+
}
70+
}
71+
}
72+
return 0;
73+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#define PROBLEM \
2+
"https://judge.yosupo.jp/problem/queue_operate_all_composite"
3+
#include "../template.hpp"
4+
#include "../../../library/contest/random.hpp"
5+
#include "../../../library/data_structures_[l,r]/disjoint_rmq.hpp"
6+
#include "../../../library/data_structures_[l,r)/seg_tree.hpp"
7+
const int mod = 998'244'353;
8+
int main() {
9+
cin.tie(0)->sync_with_stdio(0);
10+
int q;
11+
cin >> q;
12+
vector<array<int, 3>> queries(q);
13+
vector<array<int, 2>> init;
14+
for (int i = 0; i < q; i++) {
15+
int type;
16+
cin >> type;
17+
if (type == 0) {
18+
int a, b;
19+
cin >> a >> b;
20+
queries[i] = {type, a, b};
21+
init.push_back({a, b});
22+
} else if (type == 1) {
23+
queries[i] = {type, -1, -1};
24+
} else {
25+
int x;
26+
cin >> x;
27+
queries[i] = {type, x, -1};
28+
}
29+
}
30+
auto f = [&](const array<int, 2>& l,
31+
const array<int, 2>& r) -> array<int, 2> {
32+
return {int(1LL * l[0] * r[0] % mod),
33+
int((1LL * r[0] * l[1] + r[1]) % mod)};
34+
};
35+
const array<int, 2> unit = {1, 0};
36+
tree st(ssize(init), unit, f);
37+
for (int i = 0; i < ssize(init); i++)
38+
st.update(i, init[i]);
39+
disjoint_rmq rmq(init, f);
40+
int l = 0, r = 0; //[l,r)
41+
for (int i = 0; i < q; i++) {
42+
int type = queries[i][0];
43+
if (type == 0) {
44+
r++;
45+
} else if (type == 1) {
46+
l++;
47+
} else {
48+
int x = queries[i][1];
49+
assert(l <= r);
50+
int which = rnd(0, 2);
51+
st.max_right(l, r,
52+
[&](int m, const array<int, 2>& val) -> bool {
53+
assert(l < m && m <= r);
54+
assert(val == rmq.query(l, m - 1));
55+
if (which == 0) return 0;
56+
else if (which == 1) return 1;
57+
else return rnd(0, 1);
58+
});
59+
st.min_left(l, r,
60+
[&](int m, const array<int, 2>& val) -> bool {
61+
assert(l <= m && m < r);
62+
assert(val == rmq.query(m, r - 1));
63+
if (which == 0) return 0;
64+
else if (which == 1) return 1;
65+
else return rnd(0, 1);
66+
});
67+
if (l == r) cout << x << '\n';
68+
else {
69+
array<int, 2> line = rmq.query(l, r - 1);
70+
cout << (1LL * line[0] * x + line[1]) % mod
71+
<< '\n';
72+
}
73+
}
74+
}
75+
return 0;
76+
}

0 commit comments

Comments
 (0)