/
rbst-sequence.test.cpp
155 lines (138 loc) · 3.07 KB
/
rbst-sequence.test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#define PROBLEM "https://judge.yosupo.jp/problem/aplusb"
//
#include "../../template/template.hpp"
//
#include "../../segment-tree/rbst-sequence.hpp"
//
#include "../../misc/rng.hpp"
using namespace Nyaan;
// min add
namespace SequenceTestImpl {
using T = ll;
using E = ll;
T f(T a, T b) { return min(a, b); }
E g(T a, E b) { return a + b; }
E h(T a, E b) { return a + b; }
T ti() { return infLL; }
E ei() { return 0; }
using Seq = Sequence<T, E, f, g, h, ti, ei>;
void test() {
Seq s;
vl v;
// constructor
if (rng(0, 2)) {
int n = rng(0, 10);
if (rng(0, 1)) {
s = Seq{n};
v = vl(n, ti());
} else {
rep(_, n) v.push_back(rng(0, TEN(9)));
s = Seq{v};
}
auto v2 = s.get_vector();
auto v3 = s.make_array();
if (v != v2) {
trc2(v);
trc2(v2);
}
assert(v == v2);
rep(i, sz(v)) assert(v3[i].fi == i);
if (s.fold_all() == ti()) v.clear(), s.clear();
}
rep(t, 1000) {
// if (t % 100 == 0) cerr << sz(v) << " ";
// if (t == 999) cerr << "\n";
int cmd = rng(0, 10);
if (cmd == 0) {
// insert
int i = rng(0, sz(v));
ll x = rng(0, TEN(9));
s.insert(i, x);
v.insert(begin(v) + i, x);
} else if (cmd == 1) {
// push_back
ll x = rng(0, TEN(9));
s.push_back(x);
v.push_back(x);
} else if (cmd == 2) {
// erase
if (sz(v) != 0) {
int i = rng(0, sz(v) - 1);
s.erase(i);
v.erase(begin(v) + i);
}
} else if (cmd == 3) {
// pop_back
if (sz(v) != 0) {
s.pop_back();
v.pop_back();
}
} else if (cmd == 4) {
// apply
int l = rng(0, sz(v));
int r = rng(0, sz(v));
if (l > r) swap(l, r);
ll x = rng(0, TEN(9));
s.apply(l, r, x);
reg(i, l, r) v[i] += x;
} else if (cmd == 5) {
// fold
int l = rng(0, sz(v));
int r = rng(0, sz(v));
if (l > r) swap(l, r);
ll f1 = s.fold(l, r);
ll f2 = ti();
reg(i, l, r) f2 = f(f2, v[i]);
/*
if (f1 != f2) {
auto w = s.get_vector();
trc2(v);
trc2(w);
trc2(l, r, f1, f2);
}
*/
assert(f1 == f2);
} else if (cmd == 6) {
// append
int n = rng(0, 15);
vector<ll> w(n);
each(x, w) x = rng(1, TEN(9));
copy(all(w), back_inserter(v));
s.append(w);
} else if (cmd == 7) {
// erase(range)
if (sz(v)) {
int l = rng(0, sz(v));
int r = rng(0, sz(v));
if (l > r) swap(l, r);
if (r - l > 8) r = l + 8;
s.erase(l, r);
v.erase(begin(v) + l, begin(v) + r);
}
}
auto v2 = s.get_vector();
auto v3 = s.make_array();
/*
if (v != v2) {
trc2(cmd);
trc2(sz(v), v);
trc2(sz(v2), v2);
}
*/
assert(v == v2);
rep(i, sz(v3)) assert(v3[i].fi == i);
}
}
} // namespace SequenceTestImpl
void q() {
rep(_, 1000) SequenceTestImpl::test();
cerr << "OK" << endl;
int a, b;
cin >> a >> b;
cout << a + b << endl;
}
void Nyaan::solve() {
int t = 1;
// in(t);
while (t--) q();
}