This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub ngthanhtrung23/ACM_Notebook_new
#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A" #include <bits/stdc++.h> using namespace std; #include "../../debug.h" #include "../container_pipe_utils.h" int main() { // min, max { vector<int> a {3, 5, 4, 1, 2}; assert((a | MIN) == 1); assert((a | MAX) == 5); vector<int64_t> a64 {3000111000111LL, 5000111000111LL, 4000111000111LL, 1000111000111LL, 2000111000111LL}; assert((a64 | MIN) == 1000111000111LL); assert((a64 | MAX) == 5000111000111LL); vector<string> as {"10", "3", "5", "4", "1"}; assert((as | MIN) == "1"); assert((as | MAX) == "5"); } // sum { vector<int> a {1000111000, 1000111000, 1000111000}; assert((a | SUM) == 3000333000LL); vector<int> a2 {1, 2, 3}; assert((a2 | SUM_XOR) == 0); vector<int> a3 {1, 2, 4}; assert((a3 | SUM_XOR) == 7); } // sort { vector<int> a {3, 5, 4, 1, 2}; a | SORT | ADD_1; assert((a == vector<int>{2, 3, 4, 5, 6})); vector<int> a2 {30, 50, 0, 40, 10, 20}; a2 | COMPRESS; assert((a2 == vector<int>{3, 5, 0, 4, 1, 2})); vector<int> a3 {2, 3, 4}; a3 | SUB_1 | PREFIX_SUM; assert((a3 == vector<int>{1, 3, 6})); vector<int> a4 {3, 2, 1}; a4 | REVERSE | SUB_1; assert((a4 == vector<int>{0, 1, 2})); } cout << "Hello World\n"; return 0; }
#line 1 "Misc/tests/pipe_utils.test.cpp" #define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A" #include <bits/stdc++.h> using namespace std; #line 1 "debug.h" #define FOR(i, a, b) for (int i = (a), _##i = (b); i <= _##i; ++i) #define REP(i, a) for (int i = 0, _##i = (a); i < _##i; ++i) #define DEBUG(X) { auto _X = (X); std::cerr << "L" << __LINE__ << ": " << #X << " = " << (_X) << std::endl; } #define PR(A, n) { std::cerr << "L" << __LINE__ << ": " << #A << " = "; FOR(_, 1, n) std::cerr << A[_] << ' '; std::cerr << std::endl; } #define PR0(A, n) { std::cerr << "L" << __LINE__ << ": " << #A << " = "; REP(_, n) std::cerr << A[_] << ' '; std::cerr << std::endl; } // For printing std::pair, container, etc. // Copied from https://quangloc99.github.io/2021/07/30/my-CP-debugging-template.html template<class U, class V> std::ostream& operator << (std::ostream& out, const std::pair<U, V>& p) { return out << '(' << p.first << ", " << p.second << ')'; } template<class Con, class = decltype(begin(std::declval<Con>()))> typename std::enable_if<!std::is_same<Con, std::string>::value, std::ostream&>::type operator << (std::ostream& out, const Con& con) { out << '{'; for (auto beg = con.begin(), it = beg; it != con.end(); it++) { out << (it == beg ? "" : ", ") << *it; } return out << '}'; } template<size_t i, class T> std::ostream& print_tuple_utils(std::ostream& out, const T& tup) { if (i == std::tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); } template<class ...U> std::ostream& operator << (std::ostream& out, const std::tuple<U...>& t) { return print_tuple_utils<0, std::tuple<U...>>(out, t); } #line 1 "Misc/container_pipe_utils.h" // Container operations, idea from https://codeforces.com/submissions/Yuu {{{ template<typename T> struct accumulator_type { using type = T; }; template<> struct accumulator_type<int32_t> { using type = int64_t; }; template<> struct accumulator_type<uint32_t> { using type = uint64_t; }; template<> struct accumulator_type<int64_t> { using type = __int128_t; }; template<> struct accumulator_type<uint64_t> { using type = __uint128_t; }; enum ReduceOp { MIN, MAX }; template<typename Container> auto operator | (const Container& a, ReduceOp op) { switch (op) { case MIN: return *min_element(a.begin(), a.end()); case MAX: return *max_element(a.begin(), a.end()); } assert(false); } enum SumOp { SUM, SUM_XOR }; template<typename Container> auto operator | (const Container& a, SumOp op) { typename accumulator_type<typename Container::value_type>::type sum{}; switch (op) { case SUM: for (const auto& elem : a) sum += elem; return sum; case SUM_XOR: for (const auto& elem : a) sum ^= elem; return sum; } assert(false); } enum ComparableOp { SORT }; template<typename Container> Container& operator | (Container& a, ComparableOp op) { __typeof(a) values; switch (op) { case SORT: std::sort(a.begin(), a.end()); break; } return a; } enum TransformOp { ADD_1, PREFIX_SUM, PREFIX_SUM_XOR, REVERSE, SUB_1, COMPRESS }; template<typename Container> Container& operator | (Container& a, TransformOp op) { __typeof(a) values; switch (op) { case ADD_1: for (auto& elem : a) elem += 1; break; case COMPRESS: values = a; std::sort(values.begin(), values.end()); values.erase(std::unique(values.begin(), values.end()), values.end()); for (auto& value : a) value = std::lower_bound(values.begin(), values.end(), value) - values.begin(); break; case PREFIX_SUM: std::partial_sum(a.begin(), a.end(), a.begin()); break; case PREFIX_SUM_XOR: std::partial_sum(a.begin(), a.end(), a.begin(), [] (int x, int y) { return x ^ y; }); break; case REVERSE: std::reverse(a.begin(), a.end()); break; case SUB_1: for (auto& elem : a) elem -= 1; break; } return a; } enum IOp { IN }; template<typename Container> Container& operator | (Container& a, IOp op) { switch (op) { case IN: for (auto& elem : a) cin >> elem; break; } return a; } enum OOp { OUT_ONE_PER_LINE, OUT_1_LINE }; template<typename Container> Container& operator | (Container& a, OOp op) { switch (op) { case OUT_1_LINE: for (size_t i = 0; i < a.size(); ++i) { if (i > 0) cout << ' '; cout << a[i]; } break; case OUT_ONE_PER_LINE: for (const auto& elem : a) cout << elem << '\n'; break; } return a; } // }}} #line 7 "Misc/tests/pipe_utils.test.cpp" int main() { // min, max { vector<int> a {3, 5, 4, 1, 2}; assert((a | MIN) == 1); assert((a | MAX) == 5); vector<int64_t> a64 {3000111000111LL, 5000111000111LL, 4000111000111LL, 1000111000111LL, 2000111000111LL}; assert((a64 | MIN) == 1000111000111LL); assert((a64 | MAX) == 5000111000111LL); vector<string> as {"10", "3", "5", "4", "1"}; assert((as | MIN) == "1"); assert((as | MAX) == "5"); } // sum { vector<int> a {1000111000, 1000111000, 1000111000}; assert((a | SUM) == 3000333000LL); vector<int> a2 {1, 2, 3}; assert((a2 | SUM_XOR) == 0); vector<int> a3 {1, 2, 4}; assert((a3 | SUM_XOR) == 7); } // sort { vector<int> a {3, 5, 4, 1, 2}; a | SORT | ADD_1; assert((a == vector<int>{2, 3, 4, 5, 6})); vector<int> a2 {30, 50, 0, 40, 10, 20}; a2 | COMPRESS; assert((a2 == vector<int>{3, 5, 0, 4, 1, 2})); vector<int> a3 {2, 3, 4}; a3 | SUB_1 | PREFIX_SUM; assert((a3 == vector<int>{1, 3, 6})); vector<int> a4 {3, 2, 1}; a4 | REVERSE | SUB_1; assert((a4 == vector<int>{0, 1, 2})); } cout << "Hello World\n"; return 0; }