summaryrefslogtreecommitdiff
path: root/datastructures/test/segmentTree.awk
diff options
context:
space:
mode:
authorGloria Mundi <gloria@gloria-mundi.eu>2024-05-01 18:07:15 +0200
committerGloria Mundi <gloria@gloria-mundi.eu>2024-05-01 18:07:15 +0200
commita24ce98f2c79d5594d171a9b294b1cf25b488ebc (patch)
treeb7f672a8a027bee24c8b926a083560ce8ac9b1ed /datastructures/test/segmentTree.awk
parent2d09c91b8e3a4482ed94fab44ec1aab42ab72da9 (diff)
improve test system, fix segment tree, add more segment tree tests
Diffstat (limited to 'datastructures/test/segmentTree.awk')
-rw-r--r--datastructures/test/segmentTree.awk74
1 files changed, 74 insertions, 0 deletions
diff --git a/datastructures/test/segmentTree.awk b/datastructures/test/segmentTree.awk
new file mode 100644
index 0000000..e863d4e
--- /dev/null
+++ b/datastructures/test/segmentTree.awk
@@ -0,0 +1,74 @@
+
+/Neutral element for combine/ {
+ print "#ifndef SEGTREE_MUL"
+ print "# ifndef SEGTREE_FIRST_NEG"
+ print
+ print "# else"
+ tmp = $0
+ sub(/0/, "numeric_limits<ll>::max()", tmp)
+ print tmp
+ print "# endif"
+ print "#else"
+ sub(/0/, "1")
+ print
+ print "#endif"
+ next
+}
+
+/modify this \+ neutral/ {
+ print "#ifndef SEGTREE_MUL"
+ print "# ifndef SEGTREE_FIRST_NEG"
+ print
+ print "# else"
+ tmp = $0
+ sub(/a \+ b/, "a < 0 ? a : min(a, b)", tmp)
+ print tmp
+ print "# endif"
+ print "#else"
+ sub(/a \+ b/, "a*b % MOD")
+ print
+ print "#endif"
+ next
+}
+
+/SegTree\(vector<T>& a\)/ {
+ print "#ifndef SEGTREE_INIT_DEFAULT"
+ print
+ getline
+ print
+ print "#else"
+ getline
+ sub(/\/\//, "")
+ print
+ getline
+ sub(/\/\//, "")
+ print
+ print "#endif"
+ next
+}
+
+/remove for range update/ {
+ print "#ifndef SEGTREE_RANGE_UPDATE"
+ print
+ getline
+ print
+ getline
+ print "\t\t}"
+ print "#endif"
+ print "\t}"
+ next
+}
+
+/void update/ {
+ print "#ifndef SEGTREE_RANGE_UPDATE"
+}
+
+/OR: range update/ {
+ print "#else"
+}
+
+/^\};$/ {
+ print "#endif"
+}
+
+{ print }