| [ | |
| { | |
| "code_id": 1, | |
| "code": "#include <algorithm>\n#include <bitset>\n#include <cassert>\n#include <climits>\n#include <cstring>\n#include <iostream>\n#include <list>\n#include <map>\n#include <memory>\n#include <queue>\n#include <random>\n#include <set>\n#include <sstream>\n#include <stack>\n#include <unordered_set>\n#include <immintrin.h>\nnamespace OY {\n#define cin OY::inputHelper<1 << 18, 1024>::getInstance()\n#define getchar() ({char c=cin.getChar_Checked();cin.next();c; })\n#define cout OY::outputHelper<1 << 20>::getInstance()\n#define putchar cout.putChar\n#define endl '\\n'\n#define putlog(...) OY::printLog(\", \", __VA_ARGS__)\ntemplate < uint64_t _BufferSize = 1 << 10, uint64_t _BlockSize = 20 >\nclass inputHelper {\npublic:\n FILE *m_filePtr;\n char m_buf[_BufferSize], *m_end, *m_cursor;\n bool m_ok;\n void flush() {\n uint64_t a = m_end - m_cursor;\n\n if (a >= _BlockSize)\n return;\n\n memmove(m_buf, m_cursor, a);\n uint64_t b = fread(m_buf + a, 1, _BufferSize - a, m_filePtr);\n m_cursor = m_buf;\n\n if (a + b < _BufferSize) {\n m_end = m_buf + a + b;\n *m_end = EOF;\n }\n }\n\npublic:\n explicit inputHelper(const char *inputFileName) : m_ok(true) {\n if (!*inputFileName)\n m_filePtr = stdin;\n else\n m_filePtr = fopen(inputFileName, \"rt\");\n\n m_end = m_cursor = m_buf + _BufferSize;\n }\n ~inputHelper() {\n fclose(m_filePtr);\n }\n static inputHelper<_BufferSize, _BlockSize> &getInstance() {\n static inputHelper<_BufferSize, _BlockSize> s_obj(\"\");\n return s_obj;\n }\n static constexpr bool isBlank(char c) {\n return c == ' ' || c == '\\t' || c == '\\n' || c == '\\r';\n }\n static constexpr bool isEndline(char c) {\n return c == '\\n' || c == EOF;\n }\n const char &getChar_Checked() {\n if (m_cursor < m_end)\n return *m_cursor;\n\n uint64_t b = fread(m_buf, 1, _BufferSize, m_filePtr);\n m_cursor = m_buf;\n\n if (b < _BufferSize) {\n m_end = m_buf + b;\n *m_end = EOF;\n }\n\n return *m_cursor;\n }\n const char &getChar_Unchecked() const {\n return *m_cursor;\n }\n void next() {\n ++m_cursor;\n }\n void setState(bool _ok) {\n m_ok = _ok;\n }\n template <typename _Tp, typename std::enable_if<std::is_signed<_Tp>::value &std::is_integral<_Tp>::value>::type * = nullptr>\n inputHelper<_BufferSize, _BlockSize> &operator>>(_Tp &ret) {\n while (isBlank(getChar_Checked()))\n next();\n\n flush();\n\n if (getChar_Unchecked() == '-') {\n next();\n\n if (isdigit(getChar_Unchecked())) {\n ret = -(getChar_Unchecked() - '0');\n\n while (next(), isdigit(getChar_Unchecked()))\n ret = ret * 10 - (getChar_Unchecked() - '0');\n } else\n m_ok = false;\n } else {\n if (isdigit(getChar_Unchecked())) {\n ret = getChar_Unchecked() - '0';\n\n while (next(), isdigit(getChar_Unchecked()))\n ret = ret * 10 + (getChar_Unchecked() - '0');\n } else\n m_ok = false;\n }\n\n return *this;\n }\n template <typename _Tp, typename std::enable_if<std::is_unsigned<_Tp>::value &std::is_integral<_Tp>::value>::type * = nullptr>\n inputHelper<_BufferSize, _BlockSize> &operator>>(_Tp &ret) {\n while (isBlank(getChar_Checked()))\n next();\n\n flush();\n\n if (isdigit(getChar_Unchecked())) {\n ret = getChar_Unchecked() - '0';\n\n while (next(), isdigit(getChar_Unchecked()))\n ret = ret * 10 + (getChar_Unchecked() - '0');\n } else\n m_ok = false;\n\n return *this;\n }\n template <typename _Tp, typename std::enable_if<std::is_floating_point<_Tp>::value>::type * = nullptr>\n inputHelper<_BufferSize, _BlockSize> &operator>>(_Tp &ret) {\n bool neg = false, integer = false, decimal = false;\n\n while (isBlank(getChar_Checked()))\n next();\n\n flush();\n\n if (getChar_Unchecked() == '-') {\n neg = true;\n next();\n }\n\n if (!isdigit(getChar_Unchecked()) && getChar_Unchecked() != '.') {\n m_ok = false;\n return *this;\n }\n\n if (isdigit(getChar_Unchecked())) {\n integer = true;\n ret = getChar_Unchecked() - '0';\n\n while (next(), isdigit(getChar_Unchecked()))\n ret = ret * 10 + (getChar_Unchecked() - '0');\n }\n\n if (getChar_Unchecked() == '.') {\n next();\n\n if (isdigit(getChar_Unchecked())) {\n if (!integer)\n ret = 0;\n\n decimal = true;\n _Tp unit = 0.1;\n ret += unit * (getChar_Unchecked() - '0');\n\n while (next(), isdigit(getChar_Unchecked())) {\n unit *= 0.1;\n ret += unit * (getChar_Unchecked() - '0');\n }\n }\n }\n\n if (!integer && !decimal)\n m_ok = false;\n else if (neg)\n ret = -ret;\n\n return *this;\n }\n inputHelper<_BufferSize, _BlockSize> &operator>>(char &ret) {\n while (isBlank(getChar_Checked()))\n next();\n\n ret = getChar_Checked();\n\n if (ret == EOF)\n m_ok = false;\n else\n next();\n\n return *this;\n }\n inputHelper<_BufferSize, _BlockSize> &operator>>(std::string &ret) {\n while (isBlank(getChar_Checked()))\n next();\n\n if (getChar_Checked() != EOF) {\n ret.clear();\n\n do {\n ret += getChar_Checked();\n next();\n } while (!isBlank(getChar_Checked()) && getChar_Unchecked() != EOF);\n } else\n m_ok = false;\n\n return *this;\n }\n explicit operator bool() {\n return m_ok;\n }\n};\ntemplate < uint64_t _BufferSize = 1 << 20 >\nclass outputHelper {\n FILE *m_filePtr = nullptr;\n char m_buf[_BufferSize], *m_end, *m_cursor;\n char m_tempBuf[50], *m_tempBufCursor, *m_tempBufDot;\n uint64_t m_floatReserve, m_floatRatio;\n\npublic:\n outputHelper(const char *outputFileName, int prec = 6) : m_end(m_buf + _BufferSize) {\n if (!*outputFileName)\n m_filePtr = stdout;\n else\n m_filePtr = fopen(outputFileName, \"wt\");\n\n m_cursor = m_buf;\n m_tempBufCursor = m_tempBuf;\n precision(prec);\n }\n static outputHelper<_BufferSize> &getInstance() {\n static outputHelper<_BufferSize> s_obj(\"\");\n return s_obj;\n }\n ~outputHelper() {\n flush();\n fclose(m_filePtr);\n }\n void precision(int prec) {\n m_floatReserve = prec;\n m_floatRatio = pow(10, prec);\n m_tempBufDot = m_tempBuf + prec;\n }\n outputHelper<_BufferSize> &flush() {\n fwrite(m_buf, 1, m_cursor - m_buf, m_filePtr);\n fflush(m_filePtr);\n m_cursor = m_buf;\n return *this;\n }\n void putChar(const char &c) {\n if (m_cursor == m_end)\n flush();\n\n *m_cursor++ = c;\n }\n void putS(const char *c) {\n while (*c)\n putChar(*c++);\n }\n template <typename _Tp, typename std::enable_if<std::is_signed<_Tp>::value &std::is_integral<_Tp>::value>::type * = nullptr>\n outputHelper<_BufferSize> &operator<<(const _Tp &ret) {\n _Tp _ret = _Tp(ret);\n\n if (_ret >= 0) {\n do {\n *m_tempBufCursor++ = '0' + _ret % 10;\n _ret /= 10;\n } while (_ret);\n\n do\n putChar(*--m_tempBufCursor);\n\n while (m_tempBufCursor > m_tempBuf);\n } else {\n putChar('-');\n\n do {\n *m_tempBufCursor++ = '0' - _ret % 10;\n _ret /= 10;\n } while (_ret);\n\n do\n putChar(*--m_tempBufCursor);\n\n while (m_tempBufCursor > m_tempBuf);\n }\n\n return *this;\n }\n template <typename _Tp, typename std::enable_if<std::is_unsigned<_Tp>::value &std::is_integral<_Tp>::value>::type * = nullptr>\n outputHelper<_BufferSize> &operator<<(const _Tp &ret) {\n _Tp _ret = _Tp(ret);\n\n do {\n *m_tempBufCursor++ = '0' + _ret % 10;\n _ret /= 10;\n } while (_ret);\n\n do\n putChar(*--m_tempBufCursor);\n\n while (m_tempBufCursor > m_tempBuf);\n\n return *this;\n }\n template <typename _Tp, typename std::enable_if<std::is_floating_point<_Tp>::value>::type * = nullptr>\n outputHelper<_BufferSize> &operator<<(const _Tp &ret) {\n if (ret < 0) {\n putChar('-');\n return *this << -ret;\n }\n\n _Tp _ret = ret * m_floatRatio;\n uint64_t integer = _ret;\n\n if (_ret - integer >= 0.4999999999)\n integer++;\n\n do {\n *m_tempBufCursor++ = '0' + integer % 10;\n integer /= 10;\n } while (integer);\n\n if (m_tempBufCursor > m_tempBufDot) {\n do\n putChar(*--m_tempBufCursor);\n\n while (m_tempBufCursor > m_tempBufDot);\n\n putChar('.');\n } else {\n putS(\"0.\");\n\n for (int i = m_tempBufDot - m_tempBufCursor; i--;)\n putChar('0');\n }\n\n do\n putChar(*--m_tempBufCursor);\n\n while (m_tempBufCursor > m_tempBuf);\n\n return *this;\n }\n outputHelper<_BufferSize> &operator<<(const char &ret) {\n putChar(ret);\n return *this;\n }\n outputHelper<_BufferSize> &operator<<(const std::string &ret) {\n putS(ret.data());\n return *this;\n }\n};\ntemplate <uint64_t _BufferSize, uint64_t _BlockSize>\ninputHelper<_BufferSize, _BlockSize> &getline(inputHelper<_BufferSize, _BlockSize> &ih, std::string &ret) {\n ret.clear();\n\n if (ih.getChar_Checked() == EOF)\n ih.setState(false);\n else {\n while (!inputHelper<_BufferSize, _BlockSize>::isEndline(ih.getChar_Checked())) {\n ret += ih.getChar_Unchecked();\n ih.next();\n }\n\n ih.next();\n }\n\n return ih;\n}\ntemplate <typename D, typename T, typename... S>\nvoid printLog(D delim, const T &x, S... rest) {\n cout << x;\n\n if (sizeof...(rest) > 0) {\n cout << delim;\n printLog(delim, rest...);\n }\n}\n}\nusing OY::getline;\nconstexpr unsigned int constexpr_primitive_root(unsigned int mod) {\n\tusing u32 = unsigned int;\n\tusing u64 = unsigned long long;\n\tif(mod == 2) return 1;\n\tu64 m = mod - 1, ds[32] = {}, idx = 0;\n\tfor (u64 i = 2; i * i <= m; ++i) {\n\t\tif (m % i == 0) {\n\t\t\tds[idx++] = i;\n\t\t\twhile (m % i == 0) m /= i;\n\t\t}\n\t}\n\tif (m != 1) ds[idx++] = m;\n\tfor (u32 _pr = 2, flg = true;; _pr++, flg = true) {\n\t\tfor (u32 i = 0; i < idx && flg; ++i) {\n\t\t\tu64 a = _pr, b = (mod - 1) / ds[i], r = 1;\n\t\t\tfor (; b; a = a * a % mod, b >>= 1)\n\t\t\t\tif (b & 1) r = r * a % mod;\n\t\t\tif (r == 1) flg = false;\n\t\t}\n\t\tif (flg == true) return _pr;\n\t}\n}\n\n\n\n\n\ntemplate <uint32_t mod>\nstruct LazyMontgomeryModInt {\n\tusing mint = LazyMontgomeryModInt;\n\tusing i32 = int32_t;\n\tusing u32 = uint32_t;\n\tusing u64 = uint64_t;\n\n\tstatic constexpr u32 get_r() {\n\t\tu32 ret = mod;\n\t\tfor (i32 i = 0; i < 4; ++i) ret *= 2 - mod * ret;\n\t\treturn ret;\n\t}\n\n\tstatic constexpr u32 r = get_r();\n\tstatic constexpr u32 n2 = -u64(mod) % mod;\n\tstatic_assert(r * mod == 1, \"invalid, r * mod != 1\");\n\tstatic_assert(mod < (1 << 30), \"invalid, mod >= 2 ^ 30\");\n\tstatic_assert((mod & 1) == 1, \"invalid, mod % 2 == 0\");\n\n\tu32 a;\n\n\tconstexpr LazyMontgomeryModInt() : a(0) {}\n\tconstexpr LazyMontgomeryModInt(const int64_t &b)\n\t\t\t: a(reduce(u64(b % mod + mod) * n2)){};\n\n\tstatic constexpr u32 reduce(const u64 &b) {\n\t\treturn (b + u64(u32(b) * u32(-r)) * mod) >> 32;\n\t}\n\n\tconstexpr mint &operator+=(const mint &b) {\n\t\tif (i32(a += b.a - 2 * mod) < 0) a += 2 * mod;\n\t\treturn *this;\n\t}\n\n\tconstexpr mint &operator-=(const mint &b) {\n\t\tif (i32(a -= b.a) < 0) a += 2 * mod;\n\t\treturn *this;\n\t}\n\n\tconstexpr mint &operator*=(const mint &b) {\n\t\ta = reduce(u64(a) * b.a);\n\t\treturn *this;\n\t}\n\n\tconstexpr mint &operator/=(const mint &b) {\n\t\t*this *= b.inv();\n\t\treturn *this;\n\t}\n\n\tconstexpr mint operator+(const mint &b) const { return mint(*this) += b; }\n\tconstexpr mint operator-(const mint &b) const { return mint(*this) -= b; }\n\tconstexpr mint operator*(const mint &b) const { return mint(*this) *= b; }\n\tconstexpr mint operator/(const mint &b) const { return mint(*this) /= b; }\n\tconstexpr bool operator==(const mint &b) const {\n\t\treturn (a >= mod ? a - mod : a) == (b.a >= mod ? b.a - mod : b.a);\n\t}\n\tconstexpr bool operator!=(const mint &b) const {\n\t\treturn (a >= mod ? a - mod : a) != (b.a >= mod ? b.a - mod : b.a);\n\t}\n\tconstexpr mint operator-() const { return mint() - mint(*this); }\n\n\tconstexpr mint pow(u64 n) const {\n\t\tmint ret(1), mul(*this);\n\t\twhile (n > 0) {\n\t\t\tif (n & 1) ret *= mul;\n\t\t\tmul *= mul;\n\t\t\tn >>= 1;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tconstexpr mint inv() const { return pow(mod - 2); }\n\n\ttemplate <typename _Ostream>\n\tfriend _Ostream &operator<<(_Ostream &os, const mint &b) {\n\t\treturn os << b.get();\n\t}\n\n\ttemplate <typename _Istream>\n\tfriend _Istream &operator>>(_Istream &is, mint &b) {\n\t\tint64_t t;\n\t\tis >> t;\n\t\tb = LazyMontgomeryModInt<mod>(t);\n\t\treturn (is);\n\t}\n\t\n\tconstexpr u32 get() const {\n\t\tu32 ret = reduce(a);\n\t\treturn ret >= mod ? ret - mod : ret;\n\t}\n\n\tstatic constexpr u32 get_mod() { return mod; }\n};\n\n#pragma GCC target(\"avx,avx2\")\nusing ymm = __m256i;\nstruct mmint {\n\tymm x;\n\tstatic mmint R, M0, M1, M2, N2;\n\n\tmmint() : x() {}\n\tinline mmint(const ymm& _x) : x(_x) {}\n\tinline mmint(unsigned int a) : x(_mm256_set1_epi32(a)) {}\n\tinline mmint(unsigned int a0, unsigned int a1, unsigned int a2,\n\t\t\t\t\t\t\t unsigned int a3, unsigned int a4, unsigned int a5,\n\t\t\t\t\t\t\t unsigned int a6, unsigned int a7)\n\t\t\t: x(_mm256_set_epi32(a7, a6, a5, a4, a3, a2, a1, a0)) {}\n\tinline operator ymm&() { return x; }\n\tinline operator const ymm&() const { return x; }\n\tinline int& operator[](int i) { return *(reinterpret_cast<int*>(&x) + i); }\n\tinline const int& operator[](int i) const {\n\t\treturn *(reinterpret_cast<const int*>(&x) + i);\n\t}\n\n\ttemplate <typename _Ostream>\n\tfriend _Ostream& operator<<(_Ostream& os, const mmint& m) {\n\t\tunsigned r = R[0], mod = M1[0];\n\t\tauto reduce1 = [&](const uint64_t& b) {\n\t\t\tunsigned res = (b + uint64_t(unsigned(b) * unsigned(-r)) * mod) >> 32;\n\t\t\treturn res >= mod ? res - mod : res;\n\t\t};\n\t\tfor (int i = 0; i < 8; i++) {\n\t\t\tos << reduce1(m[i]) << (i == 7 ? \"\" : \" \");\n\t\t}\n\t\treturn os;\n\t}\n\n\ttemplate <typename mint>\n\tstatic void set_mod() {\n\t\tR = _mm256_set1_epi32(mint::r);\n\t\tM0 = _mm256_setzero_si256();\n\t\tM1 = _mm256_set1_epi32(mint::get_mod());\n\t\tM2 = _mm256_set1_epi32(mint::get_mod() * 2);\n\t\tN2 = _mm256_set1_epi32(mint::n2);\n\t}\n\n\tstatic inline mmint reduce(const mmint& prod02, const mmint& prod13) {\n\t\tymm unpalo = _mm256_unpacklo_epi32(prod02, prod13);\n\t\tymm unpahi = _mm256_unpackhi_epi32(prod02, prod13);\n\t\tymm prodlo = _mm256_unpacklo_epi64(unpalo, unpahi);\n\t\tymm prodhi = _mm256_unpackhi_epi64(unpalo, unpahi);\n\t\tymm hiplm1 = _mm256_add_epi32(prodhi, M1);\n\t\tymm prodlohi = _mm256_shuffle_epi32(prodlo, 0xF5);\n\t\tymm lmlr02 = _mm256_mul_epu32(prodlo, R);\n\t\tymm lmlr13 = _mm256_mul_epu32(prodlohi, R);\n\t\tymm prod02_ = _mm256_mul_epu32(lmlr02, M1);\n\t\tymm prod13_ = _mm256_mul_epu32(lmlr13, M1);\n\t\tymm unpalo_ = _mm256_unpacklo_epi32(prod02_, prod13_);\n\t\tymm unpahi_ = _mm256_unpackhi_epi32(prod02_, prod13_);\n\t\tymm prod = _mm256_unpackhi_epi64(unpalo_, unpahi_);\n\t\treturn _mm256_sub_epi32(hiplm1, prod);\n\t}\n\n\tstatic inline mmint itom(const mmint& A) { return A * N2; }\n\n\tstatic inline mmint mtoi(const mmint& A) {\n\t\tymm A13 = _mm256_shuffle_epi32(A, 0xF5);\n\t\tymm lmlr02 = _mm256_mul_epu32(A, R);\n\t\tymm lmlr13 = _mm256_mul_epu32(A13, R);\n\t\tymm prod02_ = _mm256_mul_epu32(lmlr02, M1);\n\t\tymm prod13_ = _mm256_mul_epu32(lmlr13, M1);\n\t\tymm unpalo_ = _mm256_unpacklo_epi32(prod02_, prod13_);\n\t\tymm unpahi_ = _mm256_unpackhi_epi32(prod02_, prod13_);\n\t\tymm prod = _mm256_unpackhi_epi64(unpalo_, unpahi_);\n\t\tymm cmp = _mm256_cmpgt_epi32(prod, M0);\n\t\tymm dif = _mm256_and_si256(cmp, M1);\n\t\treturn _mm256_sub_epi32(dif, prod);\n\t}\n\n\tfriend inline mmint operator+(const mmint& A, const mmint& B) {\n\t\tymm apb = _mm256_add_epi32(A, B);\n\t\tymm ret = _mm256_sub_epi32(apb, M2);\n\t\tymm cmp = _mm256_cmpgt_epi32(M0, ret);\n\t\tymm add = _mm256_and_si256(cmp, M2);\n\t\treturn _mm256_add_epi32(add, ret);\n\t}\n\n\tfriend inline mmint operator-(const mmint& A, const mmint& B) {\n\t\tymm ret = _mm256_sub_epi32(A, B);\n\t\tymm cmp = _mm256_cmpgt_epi32(M0, ret);\n\t\tymm add = _mm256_and_si256(cmp, M2);\n\t\treturn _mm256_add_epi32(add, ret);\n\t}\n\n\tfriend inline mmint operator*(const mmint& A, const mmint& B) {\n\t\tymm a13 = _mm256_shuffle_epi32(A, 0xF5);\n\t\tymm b13 = _mm256_shuffle_epi32(B, 0xF5);\n\t\tymm prod02 = _mm256_mul_epu32(A, B);\n\t\tymm prod13 = _mm256_mul_epu32(a13, b13);\n\t\treturn reduce(prod02, prod13);\n\t}\n\n\tinline mmint& operator+=(const mmint& A) { return (*this) = (*this) + A; }\n\tinline mmint& operator-=(const mmint& A) { return (*this) = (*this) - A; }\n\tinline mmint& operator*=(const mmint& A) { return (*this) = (*this) * A; }\n\n\tbool operator==(const mmint& A) {\n\t\tymm sub = _mm256_sub_epi32(x, A.x);\n\t\treturn _mm256_testz_si256(sub, sub) == 1;\n\t}\n\tbool operator!=(const mmint& A) { return !((*this) == A); }\n};\nmmint mmint::R;\nmmint mmint::M0, mmint::M1, mmint::M2, mmint::N2;\n\nusing mint = LazyMontgomeryModInt<998244353>;\n\nconstexpr uint32_t mod = mint::get_mod();\nconstexpr uint32_t pr = constexpr_primitive_root(mod);\nconstexpr int level = __builtin_ctzll(mod - 1);\nmint dw[level], dy[level];\n\nvoid setwy(int k) {\n\tmint w[level], y[level];\n\tw[k - 1] = mint(pr).pow((mod - 1) / (1 << k));\n\ty[k - 1] = w[k - 1].inv();\n\tfor (int i = k - 2; i > 0; --i)\n\t\tw[i] = w[i + 1] * w[i + 1], y[i] = y[i + 1] * y[i + 1];\n\tdw[1] = w[1], dy[1] = y[1], dw[2] = w[2], dy[2] = y[2];\n\tfor (int i = 3; i < k; ++i) {\n\t\tdw[i] = dw[i - 1] * y[i - 2] * w[i];\n\t\tdy[i] = dy[i - 1] * w[i - 2] * y[i];\n\t}\n}\n\nvoid ntt(mmint* a, int k) {\n\tif (k & 1) {\n\t\tint v = 1 << (k - 4);\n\t\tfor (int j = 0; j < v; ++j) {\n\t\t\tstatic mmint ajv = a[j + v];\n\t\t\ta[j + v] = a[j] - ajv;\n\t\t\ta[j] += ajv;\n\t\t}\n\t}\n\tint u = 4;\n\tu <<= (k & 1);\n\tint v = 1 << k;\n\tv >>= 2;\n\tv >>= (k & 1);\n\tmint one = mint(1), imag = dw[1];\n\tmmint ONE{one.a}, IMAG{imag.a};\n\n\twhile (v) {\n\t\tif (v == 1) {\n\t\t\tmint W = one, X = one, Y = imag;\n\t\t\tmmint A = a[0];\n\t\t\tmmint B = {one.a, one.a, W.a,\t\t\t\t\t W.a,\n\t\t\t\t\t\t\t\t one.a, one.a, (W * dw[1]).a, (W * dw[1]).a};\n\t\t\tint jh = 0;\n\t\t\tfor (; jh < u - 8; jh += 8) {\n\t\t\t\tmmint T0 = A * B;\n\t\t\t\tmmint T0m = _mm256_sub_epi32(mmint::M2, T0);\n\t\t\t\tmmint T1 = ymm(_mm256_shuffle_ps((__m256)T0m.x, (__m256)T0.x, 0x4E));\n\t\t\t\tmmint C = {one.a, Y.a,\t\t\t\t\t one.a, X.a,\n\t\t\t\t\t\t\t\t\t one.a, (Y * dw[2]).a, one.a, (X * dw[2]).a};\n\t\t\t\tX = X * dw[2];\n\t\t\t\tmmint T2 = (T0 + T1) * C;\n\t\t\t\tX *= dw[__builtin_ctzll(jh + 8)];\n\t\t\t\tW = X * X, Y = X * imag;\n\t\t\t\tmmint T2m = _mm256_sub_epi32(mmint::M2, T2);\n\t\t\t\tmmint T3 = _mm256_shuffle_epi32(T2, 0x88);\n\t\t\t\tA = a[(jh >> 3) + 1];\n\t\t\t\tB = {one.a, one.a, W.a,\t\t\t\t\t W.a,\n\t\t\t\t\t\t one.a, one.a, (W * dw[1]).a, (W * dw[1]).a};\n\t\t\t\tmmint T4 = ymm(_mm256_shuffle_ps((__m256)T2.x, (__m256)T2m.x, 0xDD));\n\t\t\t\tmmint T5 = T3 + T4;\n\t\t\t\ta[jh >> 3] = _mm256_shuffle_epi32(T5, 0x8D);\n\t\t\t}\n\t\t\tmmint T0 = A * B;\n\t\t\tmmint T0m = _mm256_sub_epi32(mmint::M2, T0);\n\t\t\tmmint T1 = ymm(_mm256_shuffle_ps((__m256)T0m.x, (__m256)T0.x, 0x4E));\n\t\t\tmmint C = {one.a, Y.a,\t\t\t\t\t one.a, X.a,\n\t\t\t\t\t\t\t\t one.a, (Y * dw[2]).a, one.a, (X * dw[2]).a};\n\t\t\tmmint T2 = (T0 + T1) * C;\n\t\t\tmmint T2m = _mm256_sub_epi32(mmint::M2, T2);\n\t\t\tmmint T3 = _mm256_shuffle_epi32(T2, 0x88);\n\t\t\tmmint T4 = ymm(_mm256_shuffle_ps((__m256)T2.x, (__m256)T2m.x, 0xDD));\n\t\t\tmmint T5 = T3 + T4;\n\t\t\ta[jh >> 3] = _mm256_shuffle_epi32(T5, 0x8D);\n\t\t} else if (v == 4) {\n\t\t\tmint W = one, X = one, WX = one;\n\t\t\tmmint IMAG1{one.a, one.a, one.a, one.a, imag.a, imag.a, imag.a, imag.a};\n\t\t\tmmint t01 = a[0], t23 = a[1], c01{one.a}, c23{one.a};\n\t\t\tint jh = 0;\n\t\t\tfor (; jh < u - 4; jh += 4) {\n\t\t\t\tX *= dw[__builtin_ctzll(jh + 4)];\n\t\t\t\tmmint tp = t01 + t23, tm = (t01 - t23) * IMAG1;\n\t\t\t\tmmint tpm = _mm256_sub_epi32(mmint::M2, tp);\n\t\t\t\tmmint tmm = _mm256_sub_epi32(mmint::M2, tm);\n\t\t\t\tt01 = a[(jh >> 1) + 2];\n\t\t\t\tt23 = a[(jh >> 1) + 3];\n\t\t\t\tW = X * X, WX = W * X;\n\t\t\t\tc01 = {one.a, one.a, one.a, one.a, X.a, X.a, X.a, X.a};\n\t\t\t\tc23 = {W.a, W.a, W.a, W.a, WX.a, WX.a, WX.a, WX.a};\n\t\t\t\tmmint u0 = _mm256_permute2x128_si256(tp, tpm, 0x00);\n\t\t\t\tmmint u1 = _mm256_permute2x128_si256(tp, tpm, 0x31);\n\t\t\t\tmmint u2 = _mm256_permute2x128_si256(tm, tmm, 0x00);\n\t\t\t\tmmint u3 = _mm256_permute2x128_si256(tm, tmm, 0x31);\n\t\t\t\tt01 *= c01, t23 *= c23;\n\t\t\t\ta[(jh >> 1) | 0] = u0 + u1;\n\t\t\t\ta[(jh >> 1) | 1] = u2 + u3;\n\t\t\t}\n\t\t\tmmint tp = t01 + t23, tm = (t01 - t23) * IMAG1;\n\t\t\tmmint tpm = _mm256_sub_epi32(mmint::M2, tp);\n\t\t\tmmint tmm = _mm256_sub_epi32(mmint::M2, tm);\n\t\t\tmmint u0 = _mm256_permute2x128_si256(tp, tpm, 0x00);\n\t\t\tmmint u1 = _mm256_permute2x128_si256(tp, tpm, 0x31);\n\t\t\tmmint u2 = _mm256_permute2x128_si256(tm, tmm, 0x00);\n\t\t\tmmint u3 = _mm256_permute2x128_si256(tm, tmm, 0x31);\n\t\t\ta[(jh >> 1) | 0] = u0 + u1;\n\t\t\ta[(jh >> 1) | 1] = u2 + u3;\n\t\t} else {\n\t\t\tint v8 = v >> 3;\n\t\t\t{\n\t\t\t\tint j0 = 0, j1 = v8, j2 = j1 + v8, j3 = j2 + v8;\n\t\t\t\tint je = v8 - 1;\n\t\t\t\tmmint t0 = a[j0], t1 = a[j1];\n\t\t\t\tmmint t2 = a[j2], t3 = a[j3];\n\t\t\t\tfor (; j0 < je; ++j0, ++j1, ++j2, ++j3) {\n\t\t\t\t\tmmint t0p2 = t0 + t2, t1p3 = t1 + t3;\n\t\t\t\t\tmmint t0m2 = t0 - t2, t1m3 = (t1 - t3) * IMAG;\n\t\t\t\t\tt0 = a[j0 + 1], t1 = a[j1 + 1];\n\t\t\t\t\tt2 = a[j2 + 1], t3 = a[j3 + 1];\n\t\t\t\t\ta[j0] = t0p2 + t1p3, a[j1] = t0p2 - t1p3;\n\t\t\t\t\ta[j2] = t0m2 + t1m3, a[j3] = t0m2 - t1m3;\n\t\t\t\t}\n\t\t\t\tmmint t0p2 = t0 + t2, t1p3 = t1 + t3;\n\t\t\t\tmmint t0m2 = t0 - t2, t1m3 = (t1 - t3) * IMAG;\n\t\t\t\ta[j0] = t0p2 + t1p3, a[j1] = t0p2 - t1p3;\n\t\t\t\ta[j2] = t0m2 + t1m3, a[j3] = t0m2 - t1m3;\n\t\t\t}\n\t\t\tmmint W{one.a}, X{dw[2].a}, Y{one.a};\n\t\t\tfor (int jh = 4; jh < u;) {\n\t\t\t\tW = X * X, Y = X * IMAG;\n\t\t\t\tint j0 = jh * v8, j1 = j0 + v8, j2 = j1 + v8, j3 = j2 + v8;\n\t\t\t\tint je = j0 + v8 - 1;\n\t\t\t\tmmint t0, t1, t2, t3;\n\t\t\t\tt0 = a[j0], t1 = a[j1];\n\t\t\t\tt2 = a[j2] * W, t3 = a[j3] * W;\n\t\t\t\tfor (; j0 < je; ++j0, ++j1, ++j2, ++j3) {\n\t\t\t\t\tmmint t0p2 = t0 + t2, t1p3 = (t1 + t3) * X;\n\t\t\t\t\tmmint t0m2 = t0 - t2, t1m3 = (t1 - t3) * Y;\n\t\t\t\t\tt0 = a[j0 + 1], t1 = a[j1 + 1];\n\t\t\t\t\tt2 = a[j2 + 1] * W, t3 = a[j3 + 1] * W;\n\t\t\t\t\ta[j0] = t0p2 + t1p3, a[j1] = t0p2 - t1p3;\n\t\t\t\t\ta[j2] = t0m2 + t1m3, a[j3] = t0m2 - t1m3;\n\t\t\t\t}\n\t\t\t\tmmint t0p2 = t0 + t2, t1p3 = (t1 + t3) * X;\n\t\t\t\tmmint t0m2 = t0 - t2, t1m3 = (t1 - t3) * Y;\n\t\t\t\ta[j0] = t0p2 + t1p3, a[j1] = t0p2 - t1p3;\n\t\t\t\ta[j2] = t0m2 + t1m3, a[j3] = t0m2 - t1m3;\n\t\t\t\tX *= mmint{dw[__builtin_ctzll((jh += 4))].a};\n\t\t\t}\n\t\t}\n\t\tu <<= 2;\n\t\tv >>= 2;\n\t}\n}\n\nvoid intt(mmint* a, int k) {\n\tint u = 1 << k;\n\tu >>= 2;\n\tint v = 1;\n\tmint one = mint(1), imag = dy[1];\n\tmmint ONE{one.a}, IMAG{imag.a};\n\twhile (u) {\n\t\tif (v == 1) {\n\t\t\tu <<= 2;\n\t\t\tmint W = one, X = one, Y = one;\n\t\t\tfor (int jh = 0; jh < u;) {\n\t\t\t\tW = X * X, Y = X * imag;\n\t\t\t\tmmint& A = a[jh >> 3];\n\t\t\t\tmint t0, t1, t2, t3, t4, t5, t6, t7;\n\t\t\t\tt0.a = A[0], t1.a = A[1], t2.a = A[2], t3.a = A[3];\n\t\t\t\tt4.a = A[4], t5.a = A[5], t6.a = A[6], t7.a = A[7];\n\t\t\t\tmint t0p1 = t0 + t1, t2p3 = t2 + t3;\n\t\t\t\tmint t0m1 = (t0 - t1) * X, t2m3 = (t2 - t3) * Y;\n\t\t\t\tA[0] = (t0p1 + t2p3).a;\n\t\t\t\tA[1] = (t0m1 + t2m3).a;\n\t\t\t\tA[2] = ((t0p1 - t2p3) * W).a;\n\t\t\t\tA[3] = ((t0m1 - t2m3) * W).a;\n\t\t\t\tX *= dy[2], W *= dy[1], Y *= dy[2];\n\t\t\t\tmint t4p5 = t4 + t5, t6p7 = t6 + t7;\n\t\t\t\tmint t4m5 = (t4 - t5) * X, t6m7 = (t6 - t7) * Y;\n\t\t\t\tA[4] = (t4p5 + t6p7).a;\n\t\t\t\tA[5] = (t4m5 + t6m7).a;\n\t\t\t\tA[6] = ((t4p5 - t6p7) * W).a;\n\t\t\t\tA[7] = ((t4m5 - t6m7) * W).a;\n\t\t\t\tX *= dy[__builtin_ctzll(jh += 8)];\n\t\t\t}\n\t\t} else if (v == 4) {\n\t\t\tu <<= 2;\n\t\t\tmint W = one, X = one, Y = one;\n\n\t\t\tfor (int jh = 0; jh < u;) {\n\t\t\t\tW = X * X, Y = X * imag;\n\t\t\t\tmmint c23{X.a, X.a, X.a, X.a, Y.a, Y.a, Y.a, Y.a};\n\t\t\t\tmmint Ws{W.a};\n\t\t\t\tmmint t01 = a[(jh >> 1) | 0];\n\t\t\t\tmmint t23 = a[(jh >> 1) | 1];\n\t\t\t\tmmint t02 = _mm256_permute2x128_si256(t01, t23, 0x20);\n\t\t\t\tmmint t13 = _mm256_permute2x128_si256(t01, t23, 0x31);\n\t\t\t\tmmint tp = t02 + t13, tm = (t02 - t13) * c23;\n\t\t\t\tmmint u0 = _mm256_permute2x128_si256(tp, tm, 0x20);\n\t\t\t\tmmint u1 = _mm256_permute2x128_si256(tp, tm, 0x31);\n\t\t\t\ta[(jh >> 1) | 0] = u0 + u1;\n\t\t\t\ta[(jh >> 1) | 1] = (u0 - u1) * Ws;\n\t\t\t\tX *= dy[__builtin_ctzll((jh += 4))];\n\t\t\t}\n\t\t} else {\n\t\t\tint v8 = v >> 3;\n\t\t\tu <<= 2;\n\t\t\t{\n\t\t\t\tint j0 = 0, j1 = v8, j2 = j1 + v8, j3 = j2 + v8;\n\t\t\t\tint je = v8 - 1;\n\t\t\t\tmmint t0 = a[j0], t1 = a[j1];\n\t\t\t\tmmint t2 = a[j2], t3 = a[j3];\n\t\t\t\tfor (; j0 < je; ++j0, ++j1, ++j2, ++j3) {\n\t\t\t\t\tmmint t0p1 = t0 + t1, t2p3 = t2 + t3;\n\t\t\t\t\tmmint t0m1 = t0 - t1, t2m3 = (t2 - t3) * IMAG;\n\t\t\t\t\tt0 = a[j0 + 1], t1 = a[j1 + 1];\n\t\t\t\t\tt2 = a[j2 + 1], t3 = a[j3 + 1];\n\t\t\t\t\ta[j0] = t0p1 + t2p3, a[j1] = t0m1 + t2m3;\n\t\t\t\t\ta[j2] = t0p1 - t2p3, a[j3] = t0m1 - t2m3;\n\t\t\t\t}\n\t\t\t\tmmint t0p1 = t0 + t1, t2p3 = t2 + t3;\n\t\t\t\tmmint t0m1 = t0 - t1, t2m3 = (t2 - t3) * IMAG;\n\t\t\t\ta[j0] = t0p1 + t2p3, a[j1] = t0m1 + t2m3;\n\t\t\t\ta[j2] = t0p1 - t2p3, a[j3] = t0m1 - t2m3;\n\t\t\t}\n\t\t\tmmint W{one.a}, X{dy[2].a}, Y{one.a};\n\t\t\tfor (int jh = 4; jh < u;) {\n\t\t\t\tW = X * X, Y = X * IMAG;\n\t\t\t\tint j0 = jh * v8, j1 = j0 + v8, j2 = j1 + v8, j3 = j2 + v8;\n\t\t\t\tint je = j0 + v8 - 1;\n\t\t\t\tmmint t0 = a[j0], t1 = a[j1];\n\t\t\t\tmmint t2 = a[j2], t3 = a[j3];\n\t\t\t\tfor (; j0 < je; ++j0, ++j1, ++j2, ++j3) {\n\t\t\t\t\tmmint t0p1 = t0 + t1, t2p3 = t2 + t3;\n\t\t\t\t\tmmint t0m1 = (t0 - t1) * X, t2m3 = (t2 - t3) * Y;\n\t\t\t\t\tt0 = a[j0 + 1], t1 = a[j1 + 1];\n\t\t\t\t\tt2 = a[j2 + 1], t3 = a[j3 + 1];\n\t\t\t\t\ta[j0] = t0p1 + t2p3, a[j1] = t0m1 + t2m3;\n\t\t\t\t\ta[j2] = (t0p1 - t2p3) * W, a[j3] = (t0m1 - t2m3) * W;\n\t\t\t\t}\n\t\t\t\tmmint t0p1 = t0 + t1, t2p3 = t2 + t3;\n\t\t\t\tmmint t0m1 = (t0 - t1) * X, t2m3 = (t2 - t3) * Y;\n\t\t\t\ta[j0] = t0p1 + t2p3, a[j1] = t0m1 + t2m3;\n\t\t\t\ta[j2] = (t0p1 - t2p3) * W, a[j3] = (t0m1 - t2m3) * W;\n\t\t\t\tX *= mmint{dy[__builtin_ctzll(jh += 4)].a};\n\t\t\t}\n\t\t}\n\t\tu >>= 4;\n\t\tv <<= 2;\n\t}\n\tif (k & 1) {\n\t\tu = 1 << k;\n\t\tu >>= 4;\n\t\tfor (int j = 0; j < u; ++j) {\n\t\t\tmmint ajv = a[j] - a[j + u];\n\t\t\ta[j] += a[j + u];\n\t\t\ta[j + u] = ajv;\n\t\t}\n\t}\n}\n\nmmint a[1 << 15], b[1 << 15];\n\nvoid inline_multiply(int M, int k) {\n\tsetwy(k);\n\tntt(a, k), ntt(b, k);\n\tfor (int i = 0; i < M >> 3; i += 8) {\n\t\ta[i + 0] *= b[i + 0];\n\t\ta[i + 1] *= b[i + 1];\n\t\ta[i + 2] *= b[i + 2];\n\t\ta[i + 3] *= b[i + 3];\n\t\ta[i + 4] *= b[i + 4];\n\t\ta[i + 5] *= b[i + 5];\n\t\ta[i + 6] *= b[i + 6];\n\t\ta[i + 7] *= b[i + 7];\n\t}\n\tintt(a, k);\n}\n\nint main() {\n\tmmint::set_mod<mint>();\n\tint n, m;\n\tunsigned int x, *p;\n\n\tcin >> n >> m, n++, m++;\n\n int i = 0;\n\tp = (unsigned int*)a;\n\tfor (i = 0; i < n; ++i, ++p) cin >> x, *p = x;\n\tp = (unsigned int*)b;\n\tfor (i = 0; i < m; ++i, ++p) cin >> x, *p = x;\n\n\tif (n + m < 1e4 && n * m <= 1e7) {\n\t\tlong long *c = new long long[n + m];\n\t\tfor (i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tc[i + j] += 1LL * a[i >> 3][i & 7] * b[j >> 3][j & 7];\n\t\t\t\tc[i + j] %= 998244353;\n\t\t\t}\n\t\t}\n\t\tfor (i = 0; i < n + m - 1; i++) cout << c[i] << \" \\n\"[i == n + m - 2];\n\t\treturn 0;\n\t}\n\n\tint k = 2, M = 4, l = n + m - 1;\n\twhile (M < l) M <<= 1, ++k;\n\tfor (i = 0; i < n >> 3; ++i) {\n\t\ta[i] = mmint::itom(a[i]);\n\t}\n\tswitch (n & 7) {\n case 7: a[i] = mmint::itom(a[i]), i++;\n case 6: a[i] = mmint::itom(a[i]), i++;\n case 5: a[i] = mmint::itom(a[i]), i++;\n case 4: a[i] = mmint::itom(a[i]), i++;\n case 3: a[i] = mmint::itom(a[i]), i++;\n case 2: a[i] = mmint::itom(a[i]), i++;\n case 1: a[i] = mmint::itom(a[i]), i++;\n\t}\n\tfor (int i = 0; i < m >> 3; ++i) {\n\t\tb[i] = mmint::itom(b[i]);\n\t}\n\tswitch (m & 7) {\n case 7: b[i] = mmint::itom(b[i]), i++;\n case 6: b[i] = mmint::itom(b[i]), i++;\n case 5: b[i] = mmint::itom(b[i]), i++;\n case 4: b[i] = mmint::itom(b[i]), i++;\n case 3: b[i] = mmint::itom(b[i]), i++;\n case 2: b[i] = mmint::itom(b[i]), i++;\n case 1: b[i] = mmint::itom(b[i]), i++;\n\t}\n\tinline_multiply(M, k);\n\tmmint im{(mint(M).inv()).a};\n\tfor (int i = 0; i < M >> 3; ++i) {\n\t\ta[i] *= im;\n\t\ta[i] = mmint::mtoi(a[i]);\n\t}\n\n\tp = (unsigned int*)a;\n\tcout << *p;\n\tp++;\n\tfor (int i = 1; i < l; i++, p++) {\n\t\tcout << ' ' << *p;\n\t}\n}", | |
| "status": [ | |
| "CE" | |
| ], | |
| "details": [ | |
| "/tmp/_my_pojcqz7jtw1/85f3bdc4-e1c2-4d90-8607-24ca9ee9fd78.cpp: In function ‘mmint operator*(const mmint&, const mmint&)’:\n/tmp/_my_pojcqz7jtw1/85f3bdc4-e1c2-4d90-8607-24ca9ee9fd78.cpp:605:51: warning: AVX vector return without AVX enabled changes the ABI [-Wpsabi]\n 605 | ymm prod02 = _mm256_mul_epu32(A, B);\n | ^\nIn file included from /usr/lib/gcc/x86_64-linux-gnu/12/include/immintrin.h:47,\n from /tmp/_my_pojcqz7jtw1/85f3bdc4-e1c2-4d90-8607-24ca9ee9fd78.cpp:16:\n/usr/lib/gcc/x86_64-linux-gnu/12/include/avx2intrin.h: In function ‘mmint operator+(const mmint&, const mmint&)’:\n/usr/lib/gcc/x86_64-linux-gnu/12/include/avx2intrin.h:119:1: error: inlining failed in call to ‘always_inline’ ‘__m256i _mm256_add_epi32(__m256i, __m256i)’: target specific option mismatch\n 119 | _mm256_add_epi32 (__m256i __A, __m256i __B)\n | ^~~~~~~~~~~~~~~~\n/tmp/_my_pojcqz7jtw1/85f3bdc4-e1c2-4d90-8607-24ca9ee9fd78.cpp:592:40: note: called from here\n 592 | return _mm256_add_epi32(add, ret);\n | ~~~~~~~~~~~~~~~~^~~~~~~~~~\n/usr/lib/gcc/x86_64-linux-gnu/12/include/avx2intrin.h:179:1: error: inlining failed in call to ‘always_inline’ ‘__m256i _mm256_and_si256(__m256i, __m256i)’: target specific option mismatch\n 179 | _mm256_and_si256 (__m256i __A, __m256i __B)\n | ^~~~~~~~~~~~~~~~\n/tmp/_my_pojcqz7jtw1/85f3bdc4-e1c2-4d90-8607-24ca9ee9fd78.cpp:591:43: note: called from here\n 591 | ymm add = _mm256_and_si256(cmp, M2);\n | ~~~~~~~~~~~~~~~~^~~~~~~~~\n/usr/lib/gcc/x86_64-linux-gnu/12/include/avx2intrin.h:273:1: error: inlining failed in call to ‘always_inline’ ‘__m256i _mm256_cmpgt_epi32(__m256i, __m256i)’: target specific option mismatch\n 273 | _mm256_cmpgt_epi32 (__m256i __A, __m256i __B)\n | ^~~~~~~~~~~~~~~~~~\n/tmp/_my_pojcqz7jtw1/85f3bdc4-e1c2-4d90-8607-24ca9ee9fd78.cpp:590:45: note: called from here\n 590 | ymm cmp = _mm256_cmpgt_epi32(M0, ret);\n | ~~~~~~~~~~~~~~~~~~^~~~~~~~~\n/usr/lib/gcc/x86_64-linux-gnu/12/include/avx2intrin.h:815:1: error: inlining failed in call to ‘always_inline’ ‘__m256i _mm256_sub_epi32(__m256i, __m256i)’: target specific option mismatch\n 815 | _mm256_sub_epi32 (__m256i __A, __m256i __B)\n | ^~~~~~~~~~~~~~~~\n/tmp/_my_pojcqz7jtw1/85f3bdc4-e1c2-4d90-8607-24ca9ee9fd78.cpp:589:43: note: called from here\n 589 | ymm ret = _mm256_sub_epi32(apb, M2);\n | ~~~~~~~~~~~~~~~~^~~~~~~~~\n/usr/lib/gcc/x86_64-linux-gnu/12/include/avx2intrin.h:119:1: error: inlining failed in call to ‘always_inline’ ‘__m256i _mm256_add_epi32(__m256i, __m256i)’: target specific option mismatch\n 119 | _mm256_add_epi32 (__m256i __A, __m256i __B)\n | ^~~~~~~~~~~~~~~~\n/tmp/_my_pojcqz7jtw1/85f3bdc4-e1c2-4d90-8607-24ca9ee9fd78.cpp:588:43: note: called from here\n 588 | ymm apb = _mm256_add_epi32(A, B);\n | ~~~~~~~~~~~~~~~~^~~~~~\n" | |
| ], | |
| "tcb_id": "多项式乘法", | |
| "query": "# 多项式乘法\n## 题目描述\n\r\n\r\n输入两个多项式,输出这两个多项式的乘积。\n## 输入格式\n第一行两个整数 $ n $ 和 $ m $,分别表示两个多项式的次数。\r\n\r\n第二行 $ n + 1 $ 个整数,分别表示第一个多项式的 $ 0 $ 到 $ n $ 次项前的系数。\r\n\r\n第三行 $ m + 1 $ 个整数,分别表示第二个多项式的 $ 0 $ 到 $ m $ 次项前的系数。\n## 输出格式\n一行 $ n + m + 1 $ 个整数,分别表示乘起来后的多项式的 $ 0 $ 到 $ n + m $ 次项前的系数。\n## 样例\n输入:\n1 2\n1 2\n1 2 1\n输出:\n1 4 5 2\n\n\n## 数据范围与提示\n$ 0 \\leq n, m \\leq 10 ^ 5 $,保证输入中的系数大于等于 $ 0 $ 且小于等于 $ 9 $。", | |
| "sample": { | |
| "input": "1 2\n1 2\n1 2 1", | |
| "output": "1 4 5 2" | |
| } | |
| }, | |
| { | |
| "code_id": 9, | |
| "code": "// {'input': '3\\nabaaaba\\n2\\n4 7\\n1 3\\n1\\n3 4\\n1\\n2 1\\nabaaaba\\n2\\n4 7\\n1 3\\n1\\n7 7\\n1\\n2 1\\nabbaabbaab\\n4\\n1 5\\n4 7\\n6 9\\n8 10\\n3\\n1 6\\n10 10\\n4 6\\n5\\n1 2\\n1 3\\n2 1\\n3 3\\n4 1', 'output': '7\\n-1\\n13'} \n#include<bits/stdc++.h>\n\nusing namespace std;\n\nconst int maxn=200100;\n\nchar s[maxn];int n,na,nb,m,la[maxn],ra[maxn],lb[maxn],rb[maxn];\n\nint ch[maxn<<1][26],link_array[maxn<<1],len[maxn<<1],lst,samtot,fa[maxn<<1][20],pos[maxn];\n\ninline void extend(int x)\n\n{\n\n\tint cur=++samtot,p=lst;\n\n\tlen[cur]=len[p]+1;\n\n\twhile(p&&ch[p][x]==0) ch[p][x]=cur,p=link_array[p];\n\n\tif(!p) link_array[cur]=1;\n\n\telse\n\n\t{\n\n\t\tint q=ch[p][x];\n\n\t\tif(len[q]==len[p]+1) link_array[cur]=q;\n\n\t\telse\n\n\t\t{\n\n\t\t\tint clone=++samtot;\n\n\t\t\tmemcpy(ch[clone],ch[q],sizeof(ch[q]));\n\n\t\t\tlink_array[clone]=link_array[q];\n\n\t\t\tlen[clone]=len[p]+1;\n\n\t\t\twhile(p&&ch[p][x]==q) ch[p][x]=clone,p=link_array[p];\n\n\t\t\tlink_array[cur]=link_array[q]=clone;\n\n\t\t}\n\n\t}\n\n\tlst=cur;\n\n}\n\nstruct Node {int len,id,isa;};\n\nvector<Node> V[maxn<<1];\n\ninline int cmp(const Node &a,const Node &b){return a.len<b.len;}\n\nint head[maxn*5],nxt[maxn*20],ver[maxn*20],tot,q[maxn*4],he,ta,ind[maxn*5];long long val[maxn*5];\n\ninline void addedge(int a,int b){nxt[++tot]=head[a];ver[tot]=b;head[a]=tot;ind[b]++;}\n\ninline int getv(int id)\n\n{\n\n\tif(id<=samtot+na+nb) return 0;\n\n\treturn ra[id-samtot-na-nb]-la[id-samtot-na-nb]+1;\n\n}\n\nint tlen[maxn],tid[maxn];\n\ninline void solve()\n\n{\n\n\tscanf(\"%s\",s+1);n=strlen(s+1);\n\n\treverse(s+1,s+n+1);\n\n\tfor(int i=1;i<=n*5;i++) head[i]=ind[i]=val[i]=0;tot=0;\n\n\tfor(int i=1;i<=n+n;i++) memset(ch[i],0,sizeof(ch[i])),link_array[i]=len[i]=0;\n\n\tsamtot=lst=1;\n\n\tfor(int i=1;i<=n;i++) extend(s[i]-'a'),pos[i]=lst;\n\n\tfor(int i=1;i<=samtot;i++) fa[i][0]=link_array[i];\n\n\tfor(int j=1;j<20;j++) for(int i=1;i<=samtot;i++) fa[i][j]=fa[fa[i][j-1]][j-1];\n\n\tfor(int i=1;i<=n+n;i++) V[i].clear();\n\n\tscanf(\"%d\",&na);\n\n\tfor(int i=1;i<=na;i++)\n\n\t{\n\n\t\tscanf(\"%d%d\",la+i,ra+i),la[i]=n-la[i]+1,ra[i]=n-ra[i]+1;\n\n\t\tswap(la[i],ra[i]);int now=pos[ra[i]];\n\n\t\tfor(int j=19;j>=0;j--) if(len[fa[now][j]]>=ra[i]-la[i]+1) now=fa[now][j];\n\n\t\tV[now].push_back((Node){ra[i]-la[i]+1,i,1});\n\n\t}\n\n\tscanf(\"%d\",&nb);\n\n\tfor(int i=1;i<=nb;i++)\n\n\t{\n\n\t\tscanf(\"%d%d\",lb+i,rb+i),lb[i]=n-lb[i]+1,rb[i]=n-rb[i]+1;\n\n\t\tswap(lb[i],rb[i]);int now=pos[rb[i]];\n\n\t\tfor(int j=19;j>=0;j--) if(len[fa[now][j]]>=rb[i]-lb[i]+1) now=fa[now][j];\n\n\t\tV[now].push_back((Node){rb[i]-lb[i]+1,i,0});\n\n\t}\n\n\tfor(int i=2;i<=samtot;i++)\n\n\t{\n\n\t\tsort(V[i].begin(),V[i].end(),cmp);\n\n\t\tint lstv=link_array[i],ttt=0;\n\n\t\tfor(int j=0;j<(int)V[i].size();j++) if(V[i][j].isa)\n\n\t\t{\n\n\t\t\taddedge(lstv,V[i][j].id+samtot);\n\n\t\t\tttt++;tlen[ttt]=V[i][j].len;tid[ttt]=lstv=V[i][j].id+samtot;\n\n\t\t}\n\n\t\tttt++;tlen[ttt]=1000000000;tid[ttt]=i;\n\n\t\tint nowpos=1;\n\n\t\taddedge(lstv,i);\n\n\t\tfor(int j=0;j<(int)V[i].size();j++) if(!V[i][j].isa)\n\n\t\t{\n\n\t\t\tint nowlen=V[i][j].len;\n\n\t\t\twhile(tlen[nowpos]<nowlen) nowpos++;\n\n\t\t\taddedge(V[i][j].id+samtot+na,tid[nowpos]);\n\n\t\t}\n\n\t}\n\n\tscanf(\"%d\",&m);\n\n\tfor(int i=1,a,b;i<=m;i++) scanf(\"%d%d\",&a,&b),addedge(samtot+na+nb+a,samtot+na+b);\n\n\tfor(int i=1;i<=na;i++) addedge(samtot+i,samtot+na+nb+i);\n\n\the=1;ta=0;\n\n\tfor(int i=1;i<=samtot+na+na+nb;i++) if(!ind[i]) q[++ta]=i,val[i]=getv(i);\n\n\twhile(he<=ta)\n\n\t{\n\n\t\tint x=q[he++];\n\n\t\tfor(int i=head[x];i;i=nxt[i])\n\n\t\t{\n\n\t\t\tint y=ver[i];\n\n\t\t\tval[y]=max(val[y],getv(y)+val[x]);\n\n\t\t\tif(--ind[y]==0) q[++ta]=y;\n\n\t\t}\n\n\t}\n\n\tfor(int i=samtot+na+nb+1;i<=samtot+na+na+nb;i++) if(ind[i]) return (void)puts(\"-1\");\n\n\tlong long ans=0;\n\n\tfor(int i=1;i<=samtot+na+na+nb;i++) ans=max(ans,val[i]);\n\n\tprintf(\"%lld\\n\",ans);\n\n}\n\nint main()\n\n{\n\n\tint T;scanf(\"%d\",&T);\n\n\twhile(T--) solve();\n\n\treturn 0;\n\n}", | |
| "status": [ | |
| "CE" | |
| ], | |
| "details": [ | |
| "/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:10:33: error: ‘int link_array [400200]’ redeclared as different kind of entity\n 10 | int ch[maxn<<1][26],link_array[maxn<<1],len[maxn<<1],lst,samtot,fa[maxn<<1][20],pos[maxn];\n | ^\nIn file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,\n from /usr/include/signal.h:328,\n from /usr/include/c++/12/csignal:42,\n from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:43,\n from /tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:2:\n/usr/include/unistd.h:819:12: note: previous declaration ‘int link_array(const char*, const char*)’\n 819 | extern int link_array (const char *__from, const char *__to)\n | ^~~~\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp: In function ‘void extend(int)’:\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:20:52: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 20 | while(p&&ch[p][x]==0) ch[p][x]=cur,p=link_array[p];\n | ^\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:20:52: error: invalid conversion from ‘int (*)(const char*, const char*) throw ()’ {aka ‘int (*)(const char*, const char*)’} to ‘int’ [-fpermissive]\n 20 | while(p&&ch[p][x]==0) ch[p][x]=cur,p=link_array[p];\n | ~~~~~~^\n | |\n | int (*)(const char*, const char*) throw () {aka int (*)(const char*, const char*)}\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:22:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 22 | if(!p) link_array[cur]=1;\n | ^\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:22:25: error: assignment of read-only location ‘*(link_array + ((sizetype)cur))’\n 22 | if(!p) link_array[cur]=1;\n | ~~~~~~~~~^~\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:30:46: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 30 | if(len[q]==len[p]+1) link_array[cur]=q;\n | ^\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:30:47: error: assignment of read-only location ‘*(link_array + ((sizetype)cur))’\n 30 | if(len[q]==len[p]+1) link_array[cur]=q;\n | ~~~~~~~~~^~\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:40:35: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 40 | link_array[clone]=link_array[q];\n | ^\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:40:43: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 40 | link_array[clone]=link_array[q];\n | ^\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:40:36: error: assignment of read-only location ‘*(link_array + ((sizetype)clone))’\n 40 | link_array[clone]=link_array[q];\n | ~~~~~~~~~~~^~~~~~~~\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:44:70: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 44 | while(p&&ch[p][x]==q) ch[p][x]=clone,p=link_array[p];\n | ^\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:44:70: error: invalid conversion from ‘int (*)(const char*, const char*) throw ()’ {aka ‘int (*)(const char*, const char*)’} to ‘int’ [-fpermissive]\n 44 | while(p&&ch[p][x]==q) ch[p][x]=clone,p=link_array[p];\n | ~~~~~~^\n | |\n | int (*)(const char*, const char*) throw () {aka int (*)(const char*, const char*)}\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:46:33: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 46 | link_array[cur]=link_array[q]=clone;\n | ^\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:46:41: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 46 | link_array[cur]=link_array[q]=clone;\n | ^\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:46:42: error: assignment of read-only location ‘*(link_array + ((sizetype)q))’\n 46 | link_array[cur]=link_array[q]=clone;\n | ~~~~~~~^~~~~~\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp: In function ‘void solve()’:\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:88:69: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 88 | for(int i=1;i<=n+n;i++) memset(ch[i],0,sizeof(ch[i])),link_array[i]=len[i]=0;\n | ^\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:88:70: error: assignment of read-only location ‘*(link_array + ((sizetype)i))’\n 88 | for(int i=1;i<=n+n;i++) memset(ch[i],0,sizeof(ch[i])),link_array[i]=len[i]=0;\n | ~~~~~~~^~~~~~~~~\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:94:51: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 94 | for(int i=1;i<=samtot;i++) fa[i][0]=link_array[i];\n | ^\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:94:51: error: invalid conversion from ‘int (*)(const char*, const char*) throw ()’ {aka ‘int (*)(const char*, const char*)’} to ‘int’ [-fpermissive]\n 94 | for(int i=1;i<=samtot;i++) fa[i][0]=link_array[i];\n | ~~~~~~^\n | |\n | int (*)(const char*, const char*) throw () {aka int (*)(const char*, const char*)}\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:138:32: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 138 | int lstv=link_array[i],ttt=0;\n | ^\n/tmp/_my_pojxmwvdf21/912cd3eb-9741-403b-8a8b-a5b9bad55f1a.cpp:138:32: error: invalid conversion from ‘int (*)(const char*, const char*) throw ()’ {aka ‘int (*)(const char*, const char*)’} to ‘int’ [-fpermissive]\n 138 | int lstv=link_array[i],ttt=0;\n | ^\n | |\n | int (*)(const char*, const char*) throw () {aka int (*)(const char*, const char*)}\n" | |
| ], | |
| "tcb_id": "字符串问题", | |
| "query": "字符串问题\n题目描述\n#### 题目背景\r\nYazid 和 Tiffany 喜欢字符串问题。在这里,我们将给你介绍一些关于字符串的基本概念。\r\n\r\n对于一个字符串 $S$, 我们定义 $\\lvert S\\rvert$ 表示 $S$ 的长度。\r\n\r\n接着,我们定义该串的子串 $S\\left( {L,R}\\right)$ 表示由 $S$ 中从左往右数,第 $L$ 个字符到第 $R$ 个字符依次连接形成的字符串,特别地,如果 $L < 1$ 或 $R > \\lvert S\\rvert$ 或 $L > R$,则 $S\\left( {L,R}\\right)$ 表示空串。\r\n\r\n我们说两个字符串相等,当且仅当它们的长度相等,且从左至右各位上的字符依次相同。\r\n\r\n我们说一个字符串 $T$ 是 $S$ 的**前缀**,当且仅当 $S\\left( 1,\\lvert T\\rvert\\right)=T$。\r\n\r\n两个字符串 $S,T$ 相加 $S+T$ 表示的是在 $S$ 后紧挨着写下 $T$ 得到的长度为 $\\lvert S\\rvert+\\lvert T\\rvert$ 的字符串。\r\n\r\n#### 题目描述\r\n现有一个字符串 $S$。\r\n\r\nTiffany 将从中划出 $n_a$ 个子串作为 A 类串,第 $i$ 个($1\\leq i\\leq n_a$)为 $A_i = S\\left( la_i, ra_i\\right)$。\r\n\r\n类似地,Yazid 将划出 $n_b$ 个子串作为 B 类串,第 $i$ 个($1\\leq i\\leq n_b$)为 $B_i = S\\left( lb_i, rb_i\\right)$。\r\n\r\n现额外给定 $m$ 组支配关系,每组支配关系 $\\left( x,y\\right)$ 描述了第 $x$ 个 A 类串**支配**第 $y$ 个 B 类串。\r\n\r\n求一个**长度最大**的目标串 $T$,使得存在一个串 $T$ 的分割 $T=t_1 + t_2 +\\dots +t_k$($k\\geq 0$)满足:\r\n\r\n- 分割中的每个串 $t_i$ 均为 A 类串:即存在一个与其相等的 A 类串,不妨假设其为 $t_i = A_{id_i}$。\r\n- 对于分割中所有相邻的串 $t_i , t_{i+1}$($1\\leq i < k$),都有存在一个 $A_{id_i}$ 支配的 B 类串,使得该 B 类串为 $t_{i+1}$ 的前缀。\r\n\r\n方便起见,你只需要输出这个最大的长度即可。\r\n\r\n特别地,如果存在无限长的目标串(即对于任意一个正整数 $n$,都存在一个满足限制的长度超过 $n$ 的串),请输出 $-1$。\n输入格式\n从标准输入读入数据。\r\n\r\n单个测试点中包含多组数据,输入的第一行包含一个非负整数 $T$ 表示数据组数。接下来依次描述每组数据,对于每组数据:\r\n\r\n- 第 $1$ 行一个只包含小写字母的字符串 $S$。\r\n- 第 $2$ 行一个非负整数 $n_a$,表示 A 类串的数目。接下来 $n_a$ 行,每行 $2$ 个用空格隔开的整数。\r\n - 这部分中第 $i$ 行的两个数分别为 $la_i,ra_i$,描述第 $i$ 个 A 类串。\r\n - 保证 $1\\leq la_i\\leq ra_i\\leq \\lvert S\\rvert$。\r\n- 接下来一行一个非负整数 $n_b$,表示 B 类串的数目。接下来 $n_b$ 行,每行 $2$ 个用空格隔开的整数。\r\n - 这部分中第 $i$ 行的两个数分别为 $lb_i,rb_i$,描述第 $i$ 个 B 类串。\r\n - 保证 $1\\leq lb_i\\leq rb_i\\leq \\lvert S\\rvert$。\r\n- 接下来一行一个非负整数 $m$,表示支配关系的组数。接下来 $m$ 行,每行 $2$ 个用空格隔开的整数。\r\n - 这部分中每行的两个整数 $x,y$,描述一对 $\\left( x,y\\right)$ 的支配关系,具体意义见「题目描述」。\r\n - 保证 $1\\leq x\\leq n_a$,$1\\leq y\\leq n_b$。保证所有支配关系两两不同,即不存在两组支配关系的 $x,y$ **均**相同。\n输出格式\n输出到标准输出。\r\n\r\n依次输出每组数据的答案,对于每组数据:\r\n\r\n- 一行一个整数表示最大串长。特别地,如果满足限制的串可以是无限长的,则请输出 $-1$。\n样例\n输入:\n3\nabaaaba\n2\n4 7\n1 3\n1\n3 4\n1\n2 1\nabaaaba\n2\n4 7\n1 3\n1\n7 7\n1\n2 1\nabbaabbaab\n4\n1 5\n4 7\n6 9\n8 10\n3\n1 6\n10 10\n4 6\n5\n1 2\n1 3\n2 1\n3 3\n4 1\n输出:\n7\n-1\n13\n\n对于第 $1$ 组数据,A 类串有 `aaba` 与 `aba`,B 类串有 `aa`,且 $A_2$ 支配 $B_1$。我们可以找到串 `abaaaba`,它可以拆分成 $A_2 + A_1$,且 $A_1$ 包含由 $A_2$ 所支配的 $B_1$ 作为前缀。可以证明不存在长度更大的满足限制的串。\n\n对于第 $2$ 组数据,与第 $1$ 组数据唯一不同的是,唯一的 B 类串为 `a`。容易证明存在无限长的满足限制的串。\n\n对于第 $3$ 组数据,容易证明 `abbaabbaaaabb` 是最长的满足限制的串。数据范围与提示\n|$n_a$|$n_b$|$\\lvert S\\rvert$|测试点|$m$|$\\lvert A_i\\rvert \\geq \\lvert B_j\\rvert$|其他限制|\r\n|:-:|:-:|:-:|:-:|:-:|:-:|:-:|\r\n|$\\leq 100$|$\\leq 100$|$\\leq 10^4$|$1$|$\\leq 10^4$|保证|保证所有 $\\lvert A_i\\rvert,\\lvert B_j\\rvert\\leq 100$|\r\n|$\\leq 1000$|$\\leq 1000$|$\\leq 2\\times 10^5$|$2\\sim 3$|$\\leq 2\\times 10^5$|保证|无|\r\n|$=1$|$\\leq 2\\times 10^5$|$\\leq 2\\times 10^5$|$4$|$=n_b$|保证|无|\r\n|$\\leq 2\\times 10^5$|$\\leq 2\\times 10^5$|$\\leq 2\\times 10^5$|$5\\sim 6$|$\\leq 2\\times 10^5$|保证|保证所有 $ra_i +1=la_{i+1}$|\r\n|$\\leq 2\\times 10^5$|$\\leq 2\\times 10^5$|$\\leq 2\\times 10^5$|$7\\sim 8$|$\\leq 2\\times 10^5$|保证|无|\r\n|$\\leq 2\\times 10^5$|$\\leq 2\\times 10^5$|$\\leq 2\\times 10^5$|$9\\sim 10$|$\\leq 2\\times 10^5$|不保证|无|\r\n\r\n为了方便你的阅读,我们把**测试点编号**放在了表格的中间,请你注意这一点。\r\n\r\n表格中的 $\\lvert A_i\\rvert \\ge \\lvert B_j\\rvert$ 指的是**任意** B 类串的长度不超过**任意** A 类串的长度。\r\n\r\n对于所有测试点,保证:$T\\leq 100$,且对于测试点内所有数据,$\\lvert S\\rvert,n_a,n_b,m$ 的**总和**分别不会超过**该测试点中对应**的**单组数据的限制**的 $10$ 倍。比如,对于第 1 组测试点,就有 $\\sum n_a\\leq 10\\times 100=1000$ 等。特别地,我们规定对于测试点 4,有 $T\\leq 10$。\r\n\r\n对于所有测试点中的每一组数据,保证:$1\\leq \\lvert S\\rvert\\leq 2\\times 10^5$,$n_a , n_b\\leq 2\\times 10^5$,$m\\leq 2\\times 10^5$。\r\n\r\n#### 提示\r\n十二省联考命题组温馨提醒您:\r\n\r\n**数据千万条,清空第一条。**\r\n\r\n**多测不清空,爆零两行泪。**", | |
| "sample": { | |
| "input": "3\nabaaaba\n2\n4 7\n1 3\n1\n3 4\n1\n2 1\nabaaaba\n2\n4 7\n1 3\n1\n7 7\n1\n2 1\nabbaabbaab\n4\n1 5\n4 7\n6 9\n8 10\n3\n1 6\n10 10\n4 6\n5\n1 2\n1 3\n2 1\n3 3\n4 1", | |
| "output": "7\n-1\n13" | |
| } | |
| }, | |
| { | |
| "code_id": 9, | |
| "code": "// #define ONLINE_JUDGE\n#include <bits/stdc++.h>\nusing namespace std;\nconst int M = 8e5 + 5;\nconst int Inf = 0x3f3f3f3f;\ntypedef long long ll;\ntypedef std::string str;\ntypedef double db;\n#define IL inline\n#define REP(i, lim) for (int i = 1; i <= lim; ++i)\n#define MST(a, b) memset(a, b, sizeof(a))\n\ntemplate <class T>\nvoid Max(T &x, T y) {\n x = max(x, y);\n}\n\ntemplate <class T>\nvoid Min(T &x, T y) {\n x = min(x, y);\n}\nint t;\nvoid Read() {\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n cin >> t;\n}\nstruct Vec {\n db x, y;\n db len() const;\n Vec(db x_ = 0, db y_ = 0) : x(x_), y(y_){};\n Vec operator-(const Vec &b) { return Vec(x - b.x, y - b.y); }\n};\n\nconst db Eps = 1e-8;\n\nint Dcmp(db x, db y) {\n if (fabs(x - y) < Eps) {\n return 0;\n }\n return x < y ? -1 : 1;\n}\n\nstruct Node {\n int sgn;\n db v;\n Node(int s_ = 0, db v_ = 0) : sgn(s_), v(v_){};\n bool operator==(const Node &b) { return sgn == b.sgn && !Dcmp(v, b.v); }\n};\n\nVec v[M];\nNode m[M];\n\ndb Dis(const Vec &a, const Vec &b) { return hypot(a.x - b.x, a.y - b.y); }\ndb Dot(const Vec &a, const Vec &b) { return a.x * b.x + a.y * b.y; }\ndb Vec::len() const { return sqrt(Dot(*this, *this)); }\ndb Angle(const Vec &a, const Vec &b) {\n return acos(Dot(a, b) / a.len() / b.len());\n}\n\nint n;\nint Manacher(int len) {\n int p[M];\n int ret = 0;\n MST(p, 0);\n int r = 0, l = 0;\n for (int i = 1; i <= len; ++i) {\n p[i] = (i < r) ? min(p[(l << 1) - i], p[l] + l - i) : 1;\n while (/* p[i] < i && i + p[i] <= len && */ m[i + p[i]] ==\n m[i - p[i]]) {\n ++p[i];\n }\n if (p[i] + i > r) {\n r = p[i] + i;\n l = i;\n }\n if (p[i] >> 1 >= n) {\n ++ret;\n }\n int cur = p[i];\n}\n return ret / 2;\n}\nvoid Solve() {\n while (t--) {\n cin >> n;\n REP(i, n) { cin >> v[i].x >> v[i].y; }\n v[0] = v[n];\n v[n + 1] = v[1];\n int tot = 0;\n REP(i, n) {\n m[++tot] = Node();\n m[++tot] = Node(1, Angle(v[i] - v[i - 1], v[i + 1] - v[i]));\n m[++tot] = Node();\n m[++tot] = Node(2, Dis(v[i + 1], v[i]));\n }\n // for (int i = 1; i <= tot; ++i) {\n // cerr << m[i].sgn << ' ' << m[i].v << '\\n';\n // }\n REP(i, tot) { m[i + tot] = m[i]; }\n tot = (tot << 1) | 1;\n m[tot] = Node();\n cout << Manacher(tot) << '\\n';\n }\n}\n\nsigned main() {\n Read();\n Solve();\n return 0;\n}", | |
| "status": [ | |
| "CE" | |
| ], | |
| "details": [ | |
| "/tmp/_my_pojrbx8sy_3/d08cba2a-7df4-4597-85d7-b9e7f6fde18b.cpp: In function ‘int Manacher(int)’:\n/tmp/_my_pojrbx8sy_3/d08cba2a-7df4-4597-85d7-b9e7f6fde18b.cpp:82:9: error: ‘DBG’ was not declared in this scope\n 82 | DBG(i) DBG(l) DBG(r) DBG(cur) ETR;\n | ^~~\n" | |
| ], | |
| "tcb_id": "对称轴 Axes of Symmetry", | |
| "query": "# 对称轴 Axes of Symmetry\n题目描述\r\n\r\n给定一个多边形,不一定是凸多边形,但没有自交,即除了相邻的边在顶点上相交外没有两条边有公共点。\r\n\r\n求多边形的对称轴个数。\n## 输入格式\n第一行一个整数 $t (1 \\le t \\le 10)$,表示测试点个数。\r\n\r\n接下来有 $t$ 组数据,每组数据第一行有一个整数 $n (3 \\le n \\le 100\\ 000)$,表示多边形的点数。\r\n\r\n接下来 $n$ 行每行有两个整数 $x$ 和 $y$ ($-100\\ 000\\ 000 \\le x \\le 100\\ 000\\ 000$,$-100\\ 000\\ 000 \\le y \\le 100\\ 000\\ 000$),表示多边形的点。保证相邻边不共线。\n## 输出格式\n输出 $t$ 行,对每个多边形输出一个整数表示对称轴的个数。\n## 样例\n输入:\n2\n12\n1 -1\n2 -1\n2 1\n1 1\n1 2\n-1 2\n-1 1\n-2 1\n-2 -1\n-1 -1\n-1 -2\n1 -2\n6\n-1 1\n-2 0\n-1 -1\n1 -1\n2 0\n1 1\n输出:\n4\n2\n\n", | |
| "sample": { | |
| "input": "2\n12\n1 -1\n2 -1\n2 1\n1 1\n1 2\n-1 2\n-1 1\n-2 1\n-2 -1\n-1 -1\n-1 -2\n1 -2\n6\n-1 1\n-2 0\n-1 -1\n1 -1\n2 0\n1 1", | |
| "output": "4\n2" | |
| } | |
| }, | |
| { | |
| "code_id": 15, | |
| "code": "// {'input': '1\\n5 4 5\\n3 4 3 4\\n5 5 -1 5\\n-1 4 5 5\\n5 5 4 2\\n1 -1 2 4\\n1 3 1 1\\n3 2 3 3\\n4 4 4 5\\n8 9 9 5\\n7 2 6 3\\n', 'output': '9 5\\n'} \n#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long LL;\nconst LL N = 500;\n#define PII pair<LL,LL>\n#define X(x) x.first\n#define Y(x) x.second\n#define mk(x,y) make_pair(x,y)\nconst LL INF = 1e15+7;\nvoid ckmin(PII &a,PII b)\n{\n\tif(X(a)<X(b)) return;\n\tif(X(a)>X(b))\n\t{\n\t\ta=b;\n\t\treturn;\n\t}\n\tY(a)=min(Y(a),Y(b));\n} \nLL n,m,k;\nLL Make()\n{\n\treturn rand()%k+1;\n}\nLL Id(LL i,LL j)\n{\n\treturn (i-1)*m+j;\n}\nLL c[N][N],a[N],w[N][N];\nLL h[N][N];\nLL Ans1,Ans2;\nint t[N];\nLL p[N];\nLL col[N];\nPII f[N][1<<6];\nbool vis[N];\nPII operator +( PII a,PII b)\n{\n\treturn mk(X(a)+X(b),Y(a)+Y(b));\n}\nPII operator -(PII a,PII b)\n{\n\treturn mk(X(a)-X(b),Y(a)-Y(b));\n}\nbool operator >(PII a,PII b)\n{\n\tif(X(a)>X(b)) return 1;\n\tif(X(a)<X(b)) return 0;\n\treturn Y(a)>Y(b); \n}\nstruct edge\n{\n\tLL y,next;\n}e[8*N];\nLL link_array[N],tt=0;\nvoid add(LL x,LL y)\n{\n\te[++tt].y=y;\n\te[tt].next=link_array[x];\n\tlink_array[x]=tt;\n}\nvoid put(LL s)\n{\n\tfor(LL i=1;i<=k;i++)\n\tif((s>>(i-1))&1) cout<<1;\n\telse cout<<0;\n\tcout<<endl; \n}\nqueue<int> q;\nvoid dij(LL s)\n{\n\tfor(LL i=1;i<=n*m;i++)\n\tvis[i]=0;\n\twhile(!q.empty())\n\t{\n\t\tint x=q.front();\n\t\tq.pop();\n\t\tvis[x]=0;\n\t\tfor(LL i=link_array[x];i;i=e[i].next)\n\t\t{\n\t\t\tLL y=e[i].y;\n\t\t\tif(vis[y]) continue;\n\t\t\tif(f[y][s]>f[x][s]+mk(1,a[y]))\n\t\t\t{\n\t\t\t\tvis[y]=1;\n\t\t\t\tf[y][s]=f[x][s]+mk(1,a[y]);\n\t\t\t\tq.push(y);\n\t\t\t}\n\t\t}\n\t}\n}\nPII check(LL mid)\n{\n\tfor(LL i=1;i<=n;i++)\n\tfor(LL j=1;j<=m;j++)\n\t{\n\t\tif(w[i][j]>mid) a[Id(i,j)]=1;\n\t\telse a[Id(i,j)]=-1;\n\t}\n\tfor(LL i=1;i<=n*m;i++)\n\tfor(LL j=0;j<(1<<k);j++)\n\tf[i][j]=mk(INF,INF); \n\tfor(LL i=1;i<=n;i++)\n\tfor(LL j=1;j<=m;j++)\n\t{\n\t\tLL x=Id(i,j);\n\t\tif(h[i][j]==-1) continue;\n\t\tf[x][(1<<(h[i][j]-1))]=mk(1,a[x]); \n\t}\n\tfor(LL s=1;s<(1<<k);s++)\n\t{\n\t\tfor(LL i=1;i<=n*m;i++)\n\t\t{\n\t\t\tfor(LL t=s;t;t=(t-1)&s)\n\t\t\t{\n\t\t\t\tckmin(f[i][s],f[i][t]+f[i][s-t]-mk(1,a[i]));\n\t\t\t}\n\t\t\tif(f[i][s]!=mk(INF,INF)) q.push(i);\n\t\t}\n\t\tdij(s);\t\n\t}\n\tPII ans(INF,INF);\n\tfor(LL i=1;i<=n*m;i++)\n\tckmin(ans,f[i][(1<<k)-1]);\n\tif(Y(ans)<=0) Y(ans)=1;\n\telse Y(ans)=-1;\n\treturn ans; \n}\nPII Doit()\n{\n\tLL l=INF,r=-INF; \n\tfor(LL i=1;i<=n;i++)\n\t{\n\t\tfor(LL j=1;j<=m;j++)\n\t\t{\n\t\t\tl=min(l,w[i][j]);\n\t\t\tr=max(r,w[i][j]);\n\t\t\tif(c[i][j]==-1) h[i][j]=-1;\n\t\t\telse h[i][j]=col[t[c[i][j]]];\n\t\t}\t\n\t}\n\tLL cnt=X(check(0));\n\tif(cnt==INF) return\tmk(INF,INF);\n\tLL mid,ans=-1;\n\twhile(l<=r)\n\t{\n\t\tmid=(l+r)>>1;\n\t\tPII res=check(mid);\n\t\tif(Y(res)!=-1) \n\t\t{\n\t\t\tans=mid;\n\t\t\tr=mid-1;\n\t\t}\n\t\telse l=mid+1;\n\t}\n\tif(ans==-1) ans=INF;\n\treturn mk(cnt,ans);\n}\n\nvoid solve()\n{\n\tscanf(\"%lld %lld %lld\",&n,&m,&k);\n\tLL cnt=0;\n\ttt=0;\n\tfor(LL i=1;i<=n;i++)\n\tfor(LL j=1;j<=m;j++)\n\t{\n\t\tscanf(\"%lld\",&c[i][j]);\t\n\t\tlink_array[Id(i,j)]=0;\n\t\tif(t[c[i][j]]||c[i][j]==-1) continue;\n\t\tp[++cnt]=c[i][j];\n\t\tt[c[i][j]]=cnt;\t\n\t}\n\tfor(LL i=1;i<=n;i++)\n\tfor(LL j=1;j<=m;j++)\n\t{\n\t\tif(c[i][j]==-1) continue;\n\t\tif(i+1<=n&&c[i+1][j]!=-1) add(Id(i,j),Id(i+1,j));\n\t\tif(i-1>=1&&c[i-1][j]!=-1) add(Id(i,j),Id(i-1,j));\n\t\tif(j+1<=m&&c[i][j+1]!=-1) add(Id(i,j),Id(i,j+1));\n\t\tif(j-1>=1&&c[i][j-1]!=-1) add(Id(i,j),Id(i,j-1));\n\t}\n\tfor(LL i=1;i<=n;i++)\n\tfor(LL j=1;j<=m;j++)\n\tscanf(\"%lld\",&w[i][j]);\t\n\tLL T=100;\n\tPII ans(INF,INF);\n\twhile(T--)\n\t{\n\t\tfor(LL i=1;i<=cnt;i++)\n\t\tcol[i]=Make();\n\t\tckmin(ans,Doit());\n\t}\n\tif(X(ans)==INF||Y(ans)==INF) printf(\"-1\\n\");\n\telse \n\t{\n\t\tprintf(\"%lld %lld\\n\",X(ans),Y(ans));\n\t}\n\tfor(int i=1;i<=cnt;i++)\n\tt[p[i]]=0;\n}\nint main()\n{\n\tsrand(time(0));\n\tLL T;\n\tcin>>T;\n\twhile(T--)\n\t{\n\t\tsolve();\n\t}\n\treturn 0;\n}", | |
| "status": [ | |
| "CE" | |
| ], | |
| "details": [ | |
| "/tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp:56:10: error: ‘LL link_array [500]’ redeclared as different kind of entity\n 56 | LL link_array[N],tt=0;\n | ^\nIn file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,\n from /usr/include/signal.h:328,\n from /usr/include/c++/12/csignal:42,\n from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:43,\n from /tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp:2:\n/usr/include/unistd.h:819:12: note: previous declaration ‘int link_array(const char*, const char*)’\n 819 | extern int link_array (const char *__from, const char *__to)\n | ^~~~\n/tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp: In function ‘void add(LL, LL)’:\n/tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp:60:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 60 | e[tt].next=link_array[x];\n | ^\n/tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp:60:26: error: invalid conversion from ‘int (*)(const char*, const char*) noexcept’ {aka ‘int (*)(const char*, const char*)’} to ‘LL’ {aka ‘long long int’} [-fpermissive]\n 60 | e[tt].next=link_array[x];\n | ~~~~~~^\n | |\n | int (*)(const char*, const char*) noexcept {aka int (*)(const char*, const char*)}\n/tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp:61:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 61 | link_array[x]=tt;\n | ^\n/tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp:61:16: error: assignment of read-only location ‘*(link_array + ((sizetype)x))’\n 61 | link_array[x]=tt;\n | ~~~~~~~^~~\n/tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp: In function ‘void dij(LL)’:\n/tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp:80:32: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 80 | for(LL i=link_array[x];i;i=e[i].next)\n | ^\n/tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp:80:32: error: invalid conversion from ‘int (*)(const char*, const char*) noexcept’ {aka ‘int (*)(const char*, const char*)’} to ‘LL’ {aka ‘long long int’} [-fpermissive]\n 80 | for(LL i=link_array[x];i;i=e[i].next)\n | ^\n | |\n | int (*)(const char*, const char*) noexcept {aka int (*)(const char*, const char*)}\n/tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp: In function ‘void solve()’:\n/tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp:170:29: warning: pointer to a function used in arithmetic [-Wpointer-arith]\n 170 | link_array[Id(i,j)]=0;\n | ^\n/tmp/_my_pojapsaa5v1/852b2117-b551-47e1-aa82-21203ec3dd05.cpp:170:30: error: assignment of read-only location ‘*(link_array + ((sizetype)Id(i, j)))’\n 170 | link_array[Id(i,j)]=0;\n | ~~~~~~~~~~~~~^~\n" | |
| ], | |
| "tcb_id": "巧克力", | |
| "query": "巧克力\n题目描述\n「人生就像一盒巧克力,你永远不知道吃到的下一块是什么味道。」\r\n\r\n明明收到了一大块巧克力,里面有若干小块,排成 $n$ 行 $m$ 列。每一小块都有自己特别的图案 $c_{i,j}$,它们有的是海星,有的是贝壳,有的是海螺……其中还有一些因为挤压,已经分辨不出是什么图案了。明明给每一小块巧克力标上了一个美味值 $a_{i,j}$($0\\leq a_{i,j} \\leq 10^6$),这个值越大,表示这一小块巧克力越美味。\r\n\r\n正当明明咽了咽口水,准备享用美味时,舟舟神奇地出现了。看到舟舟恳求的目光,明明决定从中选出一些小块与舟舟一同分享。\r\n\r\n舟舟希望这些被选出的巧克力是连通的(两块巧克力连通当且仅当他们有公共边),而且这些巧克力要包含至少 $k$($1\\leq k\\leq 5$)种。而那些被挤压过的巧克力则是不能被选中的。\r\n\r\n明明想满足舟舟的愿望,但他又有点「抠」,想将美味尽可能多地留给自己。所以明明希望选出的巧克力块数能够尽可能地少。如果在选出的块数最少的前提下,美味值的中位数(我们定义 $n$ 个数的中位数为第 $\\left \\lfloor \\frac{n+1}{2}\\right\\rfloor$ 小的数)能够达到最小就更好了。\r\n\r\n你能帮帮明明吗?\n输入格式\n每个测试点包含多组测试数据。\r\n\r\n输入第一行包含一个正整数 $T$($1\\leq T \\leq 5$),表示测试数据组数。\r\n\r\n对于每组测试数据:\r\n\r\n输入第一行包含三个正整数 $n,m$ 和 $k$;\r\n\r\n接下来 $n$ 行,每行 $m$ 个整数,表示每小块的图案 $c_{i,j}$。若 $c_{i,j}=-1$ 表示这一小块受到过挤压,不能被选中;\r\n\r\n接下来 $n$ 行,每行 $m$ 个整数,表示每个小块的美味值 $a_{i,j}$。\n输出格式\n输出共包括 $T$ 行,每行包含两个整数,用空格隔开,即最少的块数和最小的美味值中位数。\r\n\r\n若对于某组测试数据,不存在任意一种合法的选取方案,请在对应行输出两个 $-1$。\n样例\n输入:\n1\n5 4 5\n3 4 3 4\n5 5 -1 5\n-1 4 5 5\n5 5 4 2\n1 -1 2 4\n1 3 1 1\n3 2 3 3\n4 4 4 5\n8 9 9 5\n7 2 6 3\n\n输出:\n9 5\n\n\n\n数据范围与提示 针对所有的数据 1 ≤ n×m ≤ 233, c_{i,j} = -1 或 1 ≤ c_{i,j} ≤ n×m", | |
| "sample": { | |
| "input": "1\n5 4 5\n3 4 3 4\n5 5 -1 5\n-1 4 5 5\n5 5 4 2\n1 -1 2 4\n1 3 1 1\n3 2 3 3\n4 4 4 5\n8 9 9 5\n7 2 6 3\n", | |
| "output": "9 5\n" | |
| } | |
| }, | |
| { | |
| "code_id": 3, | |
| "code": "#ifndef _MENCI_AVL_TREE_H\n\n#define _MENCI_AVL_TREE_H\n\n\n\n#include <stdbool.h>\n\n#include <stddef.h>\n\n\n\ntypedef int (*compare_function_t)(void *, void *);\n\ntypedef void (*destruct_function_t)(void *);\n\ntypedef struct _avl_node_t *avl_node_t;\n\ntypedef struct _avl_tree_t *avl_tree_t;\n\n\n\navl_tree_t avl_create(compare_function_t compare_function, destruct_function_t destruct_function);\n\nvoid avl_destroy(avl_tree_t tree);\n\nsize_t avl_size(avl_tree_t tree);\n\navl_node_t avl_insert(avl_tree_t tree, void *data);\n\nvoid *avl_get_data(avl_node_t node);\n\navl_node_t avl_find(avl_tree_t tree, void *data);\n\navl_node_t avl_find_by_order(avl_tree_t tree, int order);\n\nint avl_get_order(avl_tree_t tree, void *data);\n\nint avl_get_order_of_node(avl_node_t node);\n\nvoid avl_delete_node(avl_node_t node);\n\nbool avl_delete_data(avl_tree_t tree, void *data);\n\n\n\navl_node_t avl_lower_bound(avl_tree_t tree, void *data);\n\navl_node_t avl_upper_bound(avl_tree_t tree, void *data);\n\navl_node_t avl_node_predecessor(avl_node_t node);\n\navl_node_t avl_node_successor(avl_node_t node);\n\n\n\n#endif // _MENCI_AVL_TREE_H\n\n#ifndef _MENCI_AVL_TREE_INTERNEL_H\n\n#define _MENCI_AVL_TREE_INTERNEL_H\n\n\n\n// #include \"avl-tree.h\"\n\n\n\nstruct _avl_node_t {\n\n struct _avl_node_t *left_child;\n\n struct _avl_node_t *right_child;\n\n struct _avl_node_t *parent;\n\n\n\n // The data field.\n\n void *data;\n\n\n\n // The height of the subtree with this node as its root.\n\n int height;\n\n\n\n // The count of nodes in this subtree.\n\n size_t size;\n\n\n\n // The reference to its tree, to replace the root node when rotated to root.\n\n struct _avl_tree_t *tree;\n\n};\n\n\n\nstruct _avl_tree_t {\n\n // The root node of the tree.\n\n avl_node_t root;\n\n\n\n // The compare function, to determine the order of nodes' data.\n\n compare_function_t compare_function;\n\n\n\n // The destruct function, to destruct and free nodes' data.\n\n destruct_function_t destruct_function;\n\n};\n\n\n\ntypedef enum {\n\n LEFT = 0, RIGHT = 1\n\n} _avl_which_child_t;\n\n\n\n// Validate and print a subtree, for debugging.\n\nvoid _avl_debug(avl_node_t node, bool print, int depth);\n\n\n\n// Compare two data or node's data, compare by unsigned long if\n\n// compare_function is NULL or call the compare_function if non-NULL.\n\nint _avl_compare_data(compare_function_t compare_function, void *a, void *b);\n\nint _avl_compare_node(avl_node_t a, avl_node_t b);\n\n\n\n// Destroy a node or a subtree.\n\nvoid _avl_destroy_node(avl_node_t node);\n\nvoid _avl_destroy_subtree(avl_node_t node);\n\n\n\n// Recalculate a node's height and size after rotating, rebalancing, insertion\n\n// or deletion.\n\nvoid _avl_recalculate(avl_node_t node);\n\n\n\n// Rotate a node up, to take its parent's place.\n\n// e.g. Left rotate will let one's right-child take its place of subtree root.\n\nvoid _avl_rotate(avl_node_t node);\n\n\n\n// Do a rebalance on a subtree's root level, used when abs(balance factor) = 2.\n\nvoid _avl_rebalance(avl_node_t subtree_root, avl_node_t new_node);\n\n\n\n// Insert a node to a node's subtree.\n\nvoid _avl_insert_node(avl_node_t *subtree_root,\n\n avl_node_t parent,\n\n avl_node_t new_node);\n\n\n\ntypedef enum {\n\n // Doing a lower_bound binary search means skip all nodes less than specfied data.\n\n // So skip all nodes that compare(node->data, data) <= -1.\n\n // For the same reason, doing a upper_bound binary search skips all nodes that\n\n // compare() <= 0.\n\n // So skip nodes that compare() <= search_type will do the magic.\n\n LOWER_BOUND = -1,\n\n UPPER_BOUND = 0\n\n} _avl_search_type_t;\n\n\n\n// Binary Search a data, return found node according to search_type.\n\navl_node_t _avl_binary_search(avl_node_t root,\n\n void *data,\n\n _avl_search_type_t search_type);\n\n\n\n// Get a node's in-order predecessor or successor.\n\n// direction = LEFT means predecessor, RIGHT means successor.\n\navl_node_t _avl_neighbour(avl_node_t node, _avl_which_child_t direction);\n\n\n\n// Swap two node's position.\n\nvoid _avl_swap(avl_node_t a, avl_node_t b);\n\n\n\n// Delete a node, while maintaining the balance.\n\nvoid _avl_delete_rebalance(avl_node_t node);\n\nvoid _avl_delete(avl_node_t node);\n\n\n\nint _avl_get_order(avl_node_t node);\n\n\n\n#endif // _MENCI_AVL_TREE_INTERNEL_H\n\n// #include \"avl-tree-internel.h\"\n\n\n\n#include <assert.h>\n\n#include <stdlib.h>\n\n#include <stdio.h>\n\n\n\n#define _avl_which_child(node) \\\n\n ((node) == (node)->parent->left_child ? LEFT : RIGHT)\n\n#define _avl_get_child(node, which) \\\n\n (*((which) == LEFT ? (&(node)->left_child) : (&(node)->right_child)))\n\n#define _avl_subtree_height(node) ((node) ? ((node)->height) : 0)\n\n\n\nvoid _avl_debug(avl_node_t node, bool print, int depth) {\n\n if (!node) return;\n\n\n\n if (print && !depth) puts(\"-------------------\");\n\n\n\n int right_height = 0;\n\n size_t right_size = 0;\n\n if (node->right_child) {\n\n assert(node->right_child->parent == node);\n\n _avl_debug(node->right_child, print, depth + 1);\n\n right_height = node->right_child->height;\n\n right_size = node->right_child->size;\n\n }\n\n\n\n if (print) {\n\n for (int i = 0; i < depth; i++) fputs(\" \", stdout);\n\n printf(\"%lu\\n\", (unsigned long)node->data);\n\n }\n\n\n\n int left_height = 0;\n\n size_t left_size = 0;\n\n if (node->left_child) {\n\n assert(node->left_child->parent == node);\n\n _avl_debug(node->left_child, print, depth + 1);\n\n left_height = node->left_child->height;\n\n left_size = node->left_child->size;\n\n }\n\n\n\n\n\n if (print && !depth) puts(\"-------------------\");\n\n\n\n int max = left_height < right_height ? right_height : left_height;\n\n assert(node->height == max + 1);\n\n assert(node->size == left_size + right_size + 1);\n\n assert(abs(left_height - right_height) < 2);\n\n}\n\n\n\nint _avl_compare_data(compare_function_t compare_function, void *a, void *b) {\n\n if (a == b) return 0;\n\n if (compare_function) {\n\n return compare_function(a, b);\n\n }\n\n\n\n return (unsigned long)a < (unsigned long)b ? -1 : 1;\n\n}\n\n\n\nint _avl_compare_node(avl_node_t a, avl_node_t b) {\n\n assert(a && b && a->tree == b->tree);\n\n if (a == b) return 0;\n\n return _avl_compare_data(a->tree->compare_function, a->data, b->data);\n\n}\n\n\n\nvoid _avl_destroy_node(avl_node_t node) {\n\n if (node->tree->destruct_function) {\n\n node->tree->destruct_function(node->data);\n\n }\n\n\n\n free(node);\n\n}\n\n\n\nvoid _avl_destroy_subtree(avl_node_t node) {\n\n if (node->left_child) _avl_destroy_subtree(node->left_child);\n\n if (node->right_child) _avl_destroy_subtree(node->right_child);\n\n _avl_destroy_node(node);\n\n}\n\n\n\nvoid _avl_recalculate(avl_node_t node) {\n\n assert(node);\n\n\n\n int max_height = 0;\n\n node->size = 1;\n\n\n\n if (node->left_child) {\n\n if (node->left_child->height > max_height)\n\n max_height = node->left_child->height;\n\n node->size += node->left_child->size;\n\n }\n\n if (node->right_child) {\n\n if (node->right_child->height > max_height)\n\n max_height = node->right_child->height;\n\n node->size += node->right_child->size;\n\n }\n\n \n\n node->height = max_height + 1;\n\n}\n\n\n\nvoid _avl_rotate(avl_node_t node) {\n\n assert(node && node->parent);\n\n\n\n avl_node_t old_parent = node->parent;\n\n\n\n _avl_which_child_t which = _avl_which_child(node), another = !which;\n\n\n\n // Connect self to old parent's parent.\n\n node->parent = old_parent->parent;\n\n if (old_parent->parent)\n\n _avl_get_child(old_parent->parent, _avl_which_child(old_parent)) = node;\n\n \n\n // Connect self's another child to old parent\n\n if (_avl_get_child(node, another)) {\n\n _avl_get_child(node, another)->parent = old_parent;\n\n }\n\n _avl_get_child(old_parent, which) = _avl_get_child(node, another);\n\n\n\n // Connect old parent to self\n\n old_parent->parent = node;\n\n _avl_get_child(node, another) = old_parent;\n\n\n\n // Notice that the ancestors of old_parent's height are NOT recalculated.\n\n _avl_recalculate(old_parent);\n\n _avl_recalculate(node);\n\n\n\n // Check if rotated to root.\n\n if (!node->parent) {\n\n node->tree->root = node;\n\n }\n\n}\n\n\n\nvoid _avl_insert_node(avl_node_t *subtree_root,\n\n avl_node_t parent,\n\n avl_node_t new_node) {\n\n if (!*subtree_root) {\n\n new_node->parent = parent;\n\n *subtree_root = new_node;\n\n return;\n\n }\n\n\n\n avl_node_t current = *subtree_root;\n\n\n\n if (_avl_compare_node(new_node, current) <= 0) {\n\n // new data <= current node's data\n\n _avl_insert_node(¤t->left_child, current, new_node);\n\n\n\n // Check balance.\n\n if (_avl_subtree_height(current->left_child) - \n\n _avl_subtree_height(current->right_child) == 2) {\n\n // The balance has been broken, rebalance it.\n\n // Check which child of left-child it's inserted to.\n\n if (_avl_compare_node(new_node, current->left_child) <= 0) {\n\n // The Left-Left case.\n\n _avl_rotate(current->left_child);\n\n } else {\n\n // The Left-Right case.\n\n _avl_rotate(current->left_child->right_child);\n\n _avl_rotate(current->left_child);\n\n }\n\n }\n\n } else {\n\n // new data > current node's data\n\n _avl_insert_node(¤t->right_child, current, new_node);\n\n\n\n // Check balance.\n\n if (_avl_subtree_height(current->right_child) - \n\n _avl_subtree_height(current->left_child) == 2) {\n\n // The balance has been broken, rebalance it.\n\n // Check which child of right-child it's inserted to.\n\n if (_avl_compare_node(new_node, current->right_child) <= 0) {\n\n // The Right-Left case.\n\n _avl_rotate(current->right_child->left_child);\n\n _avl_rotate(current->right_child);\n\n } else {\n\n // The Right-Right case.\n\n _avl_rotate(current->right_child);\n\n }\n\n }\n\n }\n\n\n\n _avl_recalculate(*subtree_root);\n\n}\n\n\n\navl_node_t _avl_binary_search(avl_node_t root,\n\n void *data,\n\n _avl_search_type_t search_type) {\n\n if (!root) return NULL;\n\n\n\n int compare_result = _avl_compare_data(root->tree->compare_function,\n\n root->data,\n\n data);\n\n\n\n // Since we should find the first satisfied node, search in the left\n\n // subtree if satisfied.\n\n bool satisfied = compare_result > search_type;\n\n if (satisfied) {\n\n avl_node_t left_subtree_result = _avl_binary_search(root->left_child,\n\n data,\n\n search_type);\n\n // If a more left satisfied node was found, return it.\n\n if (left_subtree_result) return left_subtree_result;\n\n else return root;\n\n } else {\n\n return _avl_binary_search(root->right_child,\n\n data,\n\n search_type);\n\n }\n\n}\n\n\n\navl_node_t _avl_neighbour(avl_node_t node, _avl_which_child_t direction) {\n\n assert(node);\n\n\n\n // Imagine a traversal on the tree. We are on the node now and willing to\n\n // move to the in-order (or reversed in-order) next node.\n\n // e.g. find one's successor, with direction = RIGHT.\n\n if (_avl_get_child(node, direction)) {\n\n // If RIGHT subtree, find in the subtree.\n\n // Find the LEFT-most descendant of node's RIGHT subtree.\n\n node = _avl_get_child(node, direction);\n\n while (_avl_get_child(node, !direction)) {\n\n node = _avl_get_child(node, !direction);\n\n }\n\n return node;\n\n } else {\n\n // The RIGHT subtree doesn't exist, backtraces will occur.\n\n if (!node->parent) {\n\n // Backtrace reaches root. No successor found!\n\n return NULL;\n\n }\n\n\n\n while (_avl_which_child(node) == direction) {\n\n // If node is its parent's RIGHT child, after backtracing to parent,\n\n // another backtrace will occur to parent's parent.\n\n if (!node->parent->parent) {\n\n // Backtrace reaches root. No successor found!\n\n return NULL;\n\n }\n\n\n\n node = node->parent;\n\n }\n\n\n\n // If node is its parent's LEFT child, the next to be printed in the\n\n // traversal is just its parent!\n\n return node->parent;\n\n }\n\n}\n\n\n\nvoid _avl_swap(avl_node_t a, avl_node_t b) {\n\n assert(a && b);\n\n\n\n#define _avl_reconnect(parent_node, child, which) { \\\n\n if (parent_node) { \\\n\n _avl_get_child((parent_node), (which)) = (child); \\\n\n } else { \\\n\n assert(child); \\\n\n (child)->tree->root = (child); \\\n\n } \\\n\n if (child) (child)->parent = (parent_node); \\\n\n }\n\n\n\n // If one is another's parent, assume a is b's parent.\n\n if (a->parent == b) {\n\n _avl_swap(b, a);\n\n }\n\n\n\n _avl_which_child_t which_a = a->parent ? _avl_which_child(a) : LEFT,\n\n which_b = b->parent ? _avl_which_child(b) : LEFT;\n\n\n\n if (a == b->parent) {\n\n // If a is b's parent.\n\n avl_node_t c1 = _avl_get_child(b, which_b),\n\n c2 = _avl_get_child(b, !which_b),\n\n c3 = _avl_get_child(a, !which_b);\n\n \n\n _avl_reconnect(a->parent, b, which_a);\n\n\n\n _avl_reconnect(a, c1, which_b);\n\n _avl_reconnect(a, c2, !which_b);\n\n\n\n _avl_reconnect(b, a, which_b);\n\n _avl_reconnect(b, c3, !which_b);\n\n } else {\n\n avl_node_t a_l = a->left_child, a_r = a->right_child,\n\n b_l = b->left_child, b_r = b->right_child;\n\n\n\n avl_node_t a_p = a->parent, b_p = b->parent;\n\n _avl_reconnect(a_p, b, which_a);\n\n _avl_reconnect(b_p, a, which_b);\n\n\n\n _avl_reconnect(a, b_l, LEFT);\n\n _avl_reconnect(a, b_r, RIGHT);\n\n\n\n _avl_reconnect(b, a_l, LEFT);\n\n _avl_reconnect(b, a_r, RIGHT);\n\n }\n\n\n\n#undef _avl_reconnect\n\n}\n\n\n\nvoid _avl_delete_rebalance(avl_node_t node) {\n\n if (!node) return;\n\n\n\n if (_avl_subtree_height(node->left_child) - \n\n _avl_subtree_height(node->right_child) == 2) {\n\n // L - R = 2\n\n\n\n if (_avl_subtree_height(node->left_child->left_child) >=\n\n _avl_subtree_height(node->left_child->right_child)) {\n\n // The Left-Left case.\n\n _avl_rotate(node->left_child);\n\n } else {\n\n // The Left-Right case.\n\n _avl_rotate(node->left_child->right_child);\n\n _avl_rotate(node->left_child);\n\n }\n\n } else if (_avl_subtree_height(node->right_child) - \n\n _avl_subtree_height(node->left_child) == 2) {\n\n // R - L = 2\n\n\n\n if (_avl_subtree_height(node->right_child->left_child) <=\n\n _avl_subtree_height(node->right_child->right_child)) {\n\n // The Right-Right case.\n\n _avl_rotate(node->right_child);\n\n } else {\n\n // The Right-Left case.\n\n _avl_rotate(node->right_child->left_child);\n\n _avl_rotate(node->right_child);\n\n }\n\n }\n\n\n\n _avl_recalculate(node);\n\n _avl_delete_rebalance(node->parent);\n\n}\n\n\n\nvoid _avl_delete(avl_node_t node) {\n\n assert(node);\n\n\n\n while (node->left_child || node->right_child) {\n\n // Both children exist.\n\n // In this case its in-order predecessor or successor must be its descendant.\n\n // Find it's in-order predecessor or successor to take its place.\n\n avl_node_t neighbour = _avl_neighbour(node, node->left_child ? LEFT : RIGHT);\n\n\n\n // Swap the node and its neighbour.\n\n _avl_swap(node, neighbour);\n\n }\n\n\n\n // Now the node has no child, delete it.\n\n if (!node->parent) {\n\n node->tree->root = NULL;\n\n } else {\n\n _avl_get_child(node->parent, _avl_which_child(node)) = NULL;\n\n }\n\n\n\n // Since deleting a node breaks the balance, rebalance it.\n\n _avl_delete_rebalance(node->parent);\n\n\n\n _avl_destroy_node(node);\n\n}\n\n\n\nint _avl_get_order(avl_node_t node) {\n\n assert(node);\n\n \n\n int count = node->left_child ? node->left_child->size : 0;\n\n while (node->parent) {\n\n if (_avl_which_child(node) == RIGHT) {\n\n // If node is a RIGHT child, the parent and parent's LEFT subtree\n\n // is lesser than node, so add them to the count.\n\n if (node->parent->left_child) {\n\n count += node->parent->left_child->size;\n\n }\n\n count++;\n\n }\n\n\n\n node = node->parent;\n\n }\n\n\n\n return count + 1;\n\n}\n\n// #include \"avl-tree.h\"\n\n\n\n#include <stdlib.h>\n\n#include <assert.h>\n\n\n\n// #include \"avl-tree-internel.h\"\n\n\n\navl_tree_t avl_create(compare_function_t compare_function, destruct_function_t destruct_function) {\n\n avl_tree_t tree = malloc(sizeof(struct _avl_tree_t));\n\n tree->root = NULL;\n\n tree->compare_function = compare_function;\n\n tree->destruct_function = destruct_function;\n\n return tree;\n\n}\n\n\n\nvoid avl_destroy(avl_tree_t tree) {\n\n assert(tree);\n\n \n\n if (tree->root) _avl_destroy_subtree(tree->root);\n\n free(tree);\n\n}\n\n\n\nsize_t avl_size(avl_tree_t tree) {\n\n assert(tree);\n\n return tree->root ? tree->root->size : 0;\n\n}\n\n\n\navl_node_t avl_insert(avl_tree_t tree, void *data) {\n\n assert(tree);\n\n\n\n avl_node_t new_node = malloc(sizeof(struct _avl_node_t));\n\n new_node->left_child = new_node->right_child = new_node->parent = NULL;\n\n new_node->data = data;\n\n new_node->height = 1;\n\n new_node->size = 1;\n\n new_node->tree = tree;\n\n \n\n _avl_insert_node(&tree->root, NULL, new_node);\n\n\n\n return new_node;\n\n}\n\n\n\nvoid *avl_get_data(avl_node_t node) {\n\n return node->data;\n\n}\n\n\n\navl_node_t avl_find(avl_tree_t tree, void *data) {\n\n assert(tree);\n\n\n\n if (!tree->root) return NULL;\n\n\n\n avl_node_t node = avl_lower_bound(tree, data);\n\n if (node && node->data == data) return node;\n\n\n\n return NULL;\n\n}\n\n\n\navl_node_t avl_find_by_order(avl_tree_t tree, int order) {\n\n assert(tree);\n\n \n\n avl_node_t node = tree->root;\n\n\n\n // How many nodes should be skipped from the leftist of node's subtree.\n\n int count = order - 1;\n\n while (1) {\n\n if (!node) {\n\n // Not found - order isn't in [1, tree->root->size].\n\n return NULL;\n\n }\n\n\n\n int left_count = node->left_child ? node->left_child->size : 0;\n\n if (count < left_count) {\n\n // Skip part of the left subtree, not the whole left subtree.\n\n // So the node to find must be in the left subtree.\n\n node = node->left_child;\n\n } else if (count > left_count) {\n\n // The whole left subtree should be skipped, and node itself should\n\n // be skipped, too.\n\n // So skip them and find the node in the right subtree.\n\n count -= left_count + 1;\n\n node = node->right_child;\n\n } else {\n\n // The node to skip is exactly the whole left subtree.\n\n // So current node is what we're finding.\n\n return node;\n\n }\n\n }\n\n}\n\n\n\nint avl_get_order(avl_tree_t tree, void *data) {\n\n assert(tree);\n\n\n\n avl_node_t node = avl_find(tree, data);\n\n if (!node) return -1;\n\n return avl_get_order_of_node(node);\n\n}\n\n\n\nint avl_get_order_of_node(avl_node_t node) {\n\n assert(node);\n\n\n\n return _avl_get_order(node);\n\n}\n\n\n\nvoid avl_delete_node(avl_node_t node) {\n\n assert(node);\n\n\n\n _avl_delete(node);\n\n}\n\n\n\nbool avl_delete_data(avl_tree_t tree, void *data) {\n\n assert(tree);\n\n\n\n avl_node_t node = avl_find(tree, data);\n\n if (!node) return false;\n\n\n\n avl_delete_node(node);\n\n return true;\n\n}\n\n\n\navl_node_t avl_lower_bound(avl_tree_t tree, void *data) {\n\n assert(tree);\n\n return _avl_binary_search(tree->root, data, LOWER_BOUND);\n\n}\n\n\n\navl_node_t avl_upper_bound(avl_tree_t tree, void *data) {\n\n assert(tree);\n\n return _avl_binary_search(tree->root, data, UPPER_BOUND);\n\n}\n\n\n\navl_node_t avl_node_predecessor(avl_node_t node) {\n\n assert(node);\n\n return _avl_neighbour(node, LEFT);\n\n}\n\n\n\navl_node_t avl_node_successor(avl_node_t node) {\n\n assert(node);\n\n return _avl_neighbour(node, RIGHT);\n\n}\n\n// #include \"avl-tree.h\"\n\n\n\n#include <stdio.h>\n\n#include <assert.h>\n\n\n\n#define data_type_from_int(x) ((void *)(long)(x))\n\n#define data_type_to_int(x) ((int)(long)(x))\n\n\n\nint compare(void *a, void *b) {\n\n return data_type_to_int(a) - data_type_to_int(b);\n\n}\n\n\n\nint main() {\n\n avl_tree_t tree = avl_create(&compare, NULL);\n\n\n\n int n;\n\n assert(scanf(\"%d\", &n) == 1);\n\n assert(n >= 1 && n <= (int)3e5);\n\n\n\n for (int i = 0; i < n; i++) {\n\n int option, x;\n\n assert(scanf(\"%d %d\", &option, &x) == 2);\n\n assert(option >= 0 && option <= 5);\n\n\n\n if (option == 0) {\n\n avl_insert(tree, data_type_from_int(x));\n\n } else if (option == 1) {\n\n avl_delete_data(tree, data_type_from_int(x));\n\n } else if (option == 2) {\n\n avl_node_t node = avl_find_by_order(tree, x);\n\n assert(node);\n\n printf(\"%d\\n\", data_type_to_int(avl_get_data(node)));\n\n } else if (option == 3) {\n\n avl_node_t node = avl_lower_bound(tree, data_type_from_int(x));\n\n int answer;\n\n if (node) {\n\n answer = avl_get_order_of_node(node) - 1;\n\n } else {\n\n answer = avl_size(tree);\n\n }\n\n printf(\"%d\\n\", answer);\n\n } else if (option == 4) {\n\n avl_node_t node = avl_lower_bound(tree, data_type_from_int(x)),\n\n predecessor = node ? avl_node_predecessor(node) : NULL;\n\n if (predecessor) {\n\n printf(\"%d\\n\", data_type_to_int(avl_get_data(predecessor)));\n\n } else {\n\n puts(\"-1\");\n\n }\n\n } else if (option == 5) {\n\n avl_node_t successor = avl_upper_bound(tree, data_type_from_int(x));\n\n if (successor) {\n\n printf(\"%d\\n\", data_type_to_int(avl_get_data(successor)));\n\n } else {\n\n puts(\"-1\");\n\n }\n\n }\n\n }\n\n}\n\n", | |
| "status": [ | |
| "CE" | |
| ], | |
| "details": [ | |
| "/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:263:12: error: expected ‘)’ before ‘==’ token\n 263 | ((node) == (node)->parent->left_child ? LEFT : RIGHT)\n | ~ ^~~\n | )\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp: In function ‘void _avl_rotate(avl_node_t)’:\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:455:54: error: expected primary-expression before ‘,’ token\n 455 | _avl_which_child_t which = _avl_which_child(node), another = !which;\n | ^\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:465:74: error: expected primary-expression before ‘=’ token\n 465 | _avl_get_child(old_parent->parent, _avl_which_child(old_parent)) = node;\n | ^\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:471:38: error: expected primary-expression before ‘)’ token\n 471 | if (_avl_get_child(node, another)) {\n | ^\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:473:38: error: expected primary-expression before ‘->’ token\n 473 | _avl_get_child(node, another)->parent = old_parent;\n | ^~\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:477:39: error: expected primary-expression before ‘=’ token\n 477 | _avl_get_child(old_parent, which) = _avl_get_child(node, another);\n | ^\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:477:70: error: expected primary-expression before ‘;’ token\n 477 | _avl_get_child(old_parent, which) = _avl_get_child(node, another);\n | ^\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:485:35: error: expected primary-expression before ‘=’ token\n 485 | _avl_get_child(node, another) = old_parent;\n | ^\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp: In function ‘_avl_node_t* _avl_neighbour(avl_node_t, _avl_which_child_t)’:\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:677:40: error: expected primary-expression before ‘)’ token\n 677 | if (_avl_get_child(node, direction)) {\n | ^\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:683:47: error: expected primary-expression before ‘;’ token\n 683 | node = _avl_get_child(node, direction);\n | ^\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:685:48: error: expected primary-expression before ‘)’ token\n 685 | while (_avl_get_child(node, !direction)) {\n | ^\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:687:52: error: expected primary-expression before ‘;’ token\n 687 | node = _avl_get_child(node, !direction);\n | ^\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:707:39: error: expected primary-expression before ‘==’ token\n 707 | while (_avl_which_child(node) == direction) {\n | ^~\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp: In function ‘void _avl_swap(avl_node_t, avl_node_t)’:\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:749:13: error: ‘parent_node’ was not declared in this scope\n 749 | if (parent_node) { \\\n | ^~~~~~~~~~~\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:751:52: error: expected primary-expression before ‘=’ token\n 751 | _avl_get_child((parent_node), (which)) = (child); \\\n | ^\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:751:55: error: ‘child’ was not declared in this scope\n 751 | _avl_get_child((parent_node), (which)) = (child); \\\n | ^~~~~\nIn file included from /tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:253:\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:755:20: error: ‘child’ was not declared in this scope\n 755 | assert(child); \\\n | ^~~~~\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:761:13: error: ‘child’ was not declared in this scope\n 761 | if (child) (child)->parent = (parent_node); \\\n | ^~~~~\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:761:39: error: ‘parent_node’ was not declared in this scope\n 761 | if (child) (child)->parent = (parent_node); \\\n | ^~~~~~~~~~~\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp: At global scope:\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:769:5: error: expected unqualified-id before ‘if’\n 769 | if (a->parent == b) {\n | ^~\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:777:34: error: ‘a’ was not declared in this scope\n 777 | _avl_which_child_t which_a = a->parent ? _avl_which_child(a) : LEFT,\n | ^\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:783:5: error: expected unqualified-id before ‘if’\n 783 | if (a == b->parent) {\n | ^~\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp: In function ‘_avl_node_t* _avl_neighbour(avl_node_t, _avl_which_child_t)’:\n/tmp/_my_poj5gthpydr/049b3f35-6139-4836-9b8c-e7706b97141b.cpp:737:1: warning: control reaches end of non-void function [-Wreturn-type]\n 737 | }\n | ^\n" | |
| ], | |
| "tcb_id": "维护全序集", | |
| "query": "# 维护全序集\n## 题目描述\n\n\n如未特别说明,以下所有数据均为整数。\n\n维护一个多重集 $ S $ ,初始为空,有以下几种操作:\n\n1. 把 $ x $ 加入 $ S $\n2. 删除 $ S $ 中的一个 $ x $,保证删除的 $ x $ 一定存在\n3. 求 $ S $ 中第 $ k $ 小\n4. 求 $ S $ 中有多少个元素小于 $ x $\n5. 求 $ S $ 中小于 $ x $ 的最大数\n6. 求 $ S $ 中大于 $ x $ 的最小数\n\n操作共?$ n?$ 次。\n## 输入格式\n第一行一个整数?$ n $,表示共有?$ n $?次操作?。\n\n接下来?$ n $?行,每行为以下几种格式之一?:\n\n* `0?x`,把?$ x $?加入?$ S $\n* `1?x`,删除?$ S $?中的一个?$ x $,保证删除的数在?$ S $?中一定存在\n* `2?k`,求?$ S?$ 中第??$ k?$ 小的数,保证要求的数在?$ S $?中一定存在\n* `3?x`,求?$ S?$ 中有多少个数小于?$ x?$\n* `4?x`,求?$ S?$ 中小于?$ x?$ 的最大数,如果不存在,输出?$ -1?$\n* `5?x`,求?$ S?$ 中大于?$ x?$ 的最小数,如果不存在,输出?$ -1?$\n## 输出格式\n对于每次询问,输出单独一行表示答案。\n## 样例\n输入:\n5\n0 3\n0 4\n2 2\n1 4\n3 3\n输出:\n4\n0\n\n\n## 数据范围与提示\n$ 1 \\leq n \\leq 3 \\times 10 ^ 5, 0?\\leq x \\leq 10 ^ 9 $\n", | |
| "sample": { | |
| "input": "5\n0 3\n0 4\n2 2\n1 4\n3 3", | |
| "output": "4\n0" | |
| } | |
| }, | |
| { | |
| "code_id": 12, | |
| "code": "#include<bits/stdc++.h>\n#define int long long\n#define INF 0x7fffffff\n#define INF64 1e18\nusing namespace std;\n\nconstexpr int N=205;\nconstexpr int p=998244353;\n\nint n[N],m,k;\n\nstruct mat{\n\tint a[N][N];\n\tint *operator[](int x){return a[x];}\n\tmat(){memset(a,0,sizeof a);}\n\tmat operator*(mat x){\n\t\tmat res;\n\t\tfor(int i=1;i<=m;i++)\n\t\t\tfor(int l=1;l<=m;l++)\n\t\t\t\tfor(int j=1;j<=m;j++)\n\t\t\t\t\tres[i][j]+=a[i][l]*x[l][j];\n\t\treturn res;\n\t}\n\tvoid clr(){\n\t\tfor(int i=1;i<=m;i++)\n\t\t\tfor(int j=1;j<=m;j++)\n\t\t\t\ta[i][j]%=p;\n\t}\n\tvoid check(){\n\t\tfor(int i=1;i<=m;i++){\n\t\t\tfor(int j=1;j<=m;j++)\n\t\t\t\tcout<<setw(3)<<a[i][j];\n\t\t\tcout<<'\\n';\n\t\t}\n\t}\n};\n\n\nint det(mat a){\n\tint res=1;\n\tfor(int i=1;i<=n[1];i++)\n\t\tfor(int j=i+1;j<=n[1];j++){\n\t\t\twhile(a[i][i]){\n\t\t\t\tint t=a[j][i]/a[i][i];\n\t\t\t\tfor(int k=i;k<=m;k++)\n\t\t\t\t\ta[j][k]=(a[j][k]-a[i][k]*t%p+p)%p;\n\t\t\t\tswap(a.a[i],a.a[j]);res=-res;\n\t\t\t}\n\t\t\tswap(a.a[i],a.a[j]);res=-res;\n\t\t}\n\tfor(int i=1;i<=n[1];i++) res=res*a[i][i]%p;\n\treturn (res+p)%p;\n}\n\n\t\n\nint cnt[N];\n\nvoid solve(){\n\tcin>>k;\n\tfor(int i=1;i<=k;i++) cin>>n[i];\n\tm=n[1]*2;\n\tmat a;\n\tfor(int i=1;i<k;i++) cin>>cnt[i];\n\tfor(int i=1;i<k;i++){\n\t\tmat b;\n\t\tfor(int j=1;j<=cnt[i];j++){\n\t\t\tint u,v;cin>>u>>v;b[u][v]=1;\n\t\t}\n\t\tif(i==1) a=b;\n\t\telse a=a*b;\n\t\tif(i%4==0) a.clr();\n\t}\n\tcout<<det(a)<<'\\n';\n}\n\nsigned main(){\n\tios::sync_with_stdio(false);\n\tint t;cin>>t;\n\twhile(t--) solve();\n\t\n}\n\n", | |
| "status": [ | |
| "CE" | |
| ], | |
| "details": [ | |
| "/tmp/_my_pojz5lim4vg/976ac481-632d-4516-b66a-34f5e560443e.cpp: In function ‘int main()’:\n/tmp/_my_pojz5lim4vg/976ac481-632d-4516-b66a-34f5e560443e.cpp:78:14: error: ‘xpath’ was not declared in this scope\n 78 | file(xpath);\n | ^~~~~\n/tmp/_my_pojz5lim4vg/976ac481-632d-4516-b66a-34f5e560443e.cpp:78:9: error: ‘file’ was not declared in this scope\n 78 | file(xpath);\n | ^~~~\n" | |
| ], | |
| "tcb_id": "路径交点", | |
| "query": "# 路径交点\n## 题目描述\n小 L 有一个有向图,图中的顶点可以分为 $k$ 层,第 $i$ 层有 $n_i$ 个顶点,第 $1$ 层与第 $k$ 层**顶点数相同**,即 $n_1 = n_k$,且对于第 $j$($2 \\leq j \\leq k-1$)层,$n_1 \\leq n_j \\leq 2n_1$。对于第 $j$($1 \\leq j < k$)层的顶点,以它们为起点的边只会连向第 $j + 1$ 层的顶点。没有边连向第 $1$ 层的顶点,第 $k$ 层的顶点不会向其他顶点连边。\n\n现在小 L 要从这个图中选出 $n_1$ 条路径,每条路径以第 $1$ 层顶点为起点,第 $k$ 层顶点为终点,并要求**图中的每个顶点至多出现在一条路径中**。更具体地,把每一层顶点按照 $1,2,\\ldots,n_1$ 进行编号,则每条路径可以写为一个 $k$ 元组 $(p_1,p_2,\\ldots,p_k)$,表示这条路径依次经过第 $j$ 层的 $p_j$($1 \\leq p_j \\leq n_j$)号顶点,并且第 $j$($1 \\leq j < k$)层的 $p_j$ 号顶点有一条边连向第 $j+1$ 层的第 $p_{j+1}$ 号顶点。\n\n小 L 把这些路径画在了纸上,发现它们会产生若干个交点。对于两条路径 $P,Q$,分别设它们在第 $j$ 层与第 $j+1$ 层之间的连边为 $(P_j,P_{j+1})$ 与 $(Q_j,Q_{j+1})$,若,\n\n$$\n(P_j-Q_j)\\times(P_{j+1}-Q_{j+1})<0\n$$\n\n则称它们在第 $j$ 层后产生了一个交点。两条路径的交点数为它们在第 $1, 2,\\ldots,k - 1$ 层后产生的交点总数。对于整个路径方案,它的交点数为**两两不同路径间交点数之和**。\n\n\n小 L 现在想知道有偶数个交点的路径方案数比有奇数个交点的路径方案数多多少个。两个路径方案被视为相同的,当且仅当它们的 $n_1$ 条路径按第一层起点编号顺序写下的 $k$ 元组能对应相同。由于最后的结果可能很大,请你输出它对 $998244353$(一个大质数)取模后的值。\n## 输入格式。\n\n本题有多组数据,输入数据第一行一个正整数 $T$ ,表示数据组数。对于每组数据:\n\n第一行一个正整数 $k$,表示一共有 $k$ 层顶点。\n\n第二行包含 $k$ 个整数 $n_1,n_2,\\ldots,n_k$,依次表示每一层的顶点数量。保证 $n_1=n_k$,且 $n_1 \\leq n_i \\leq 2n_1$($2 \\leq i \\leq k-1$)。\n\n第三行包含 $k-1$ 个整数 $m_1,m_2,\\ldots,m_{k-1}$,依次表示第 $j$ 层顶点到第 $j+1$ 层顶点的边数。保证 $m_j \\leq n_j \\times n_{j+1}$。\n\n接下来有 $k-1$ 段输入。第 $j$($1 \\leq j < k$)段输入包含 $m_j$ 行,每一行两个整数 $u,v$,表示第 $j$ 层的 $u$ 号顶点有一条边连向第 $j+1$ 层的 $v$ 号顶点。\n\n数据保证图中不会出现重边。\n## 输出格式\n\n输出共 $T$ 行,每行一个整数,表示该组数据的答案对 $998244353$ 取模后的值。\n## 样例\n输入:\n1\n3\n2 3 2\n4 4\n1 1 \n1 2\n2 1\n2 3\n1 2\n2 1\n3 1\n3 2\n输出:\n1\n\n偶数个交点的方案有 $2$ 个,奇数个交点的方案有 $1$ 个,所以答案为 $1$。\n\n将下表中路径 $1$ 和路径 $2$ 的方案交换,将会得到相同的方案,例如路径 $1$ 为 $(2, 3, 1)$ 且路径 $2$ 为 $(1, 1, 2)$ 的方案与方案 $1$ 是相同的方案,所以不会被计入答案。\n\n| 路径方案 | 路径 $1$ | 路径 $2$ | 交点总数 |\n| :------: | :-------: | :-------: | :------: |\n| $1$ | $(1,1,2)$ | $(2,3,1)$ | $1$ |\n| $2$ | $(1,2,1)$ | $(2,1,2)$ | $2$ |\n| $3$ | $(1,2,1)$ <!-- disable merge --> | $(2,3,2)$ | $0$ |\n## 数据范围与提示\n对于所有测试数据:$2 \\leq k \\leq 100$,$2 \\leq n_1 \\leq 100$,$1 \\leq T \\leq 5$。\n\n每个测试点中,保证 $n_1 > 10$ 的数据只有 $1$ 组。", | |
| "sample": { | |
| "input": "1\n3\n2 3 2\n4 4\n1 1 \n1 2\n2 1\n2 3\n1 2\n2 1\n3 1\n3 2", | |
| "output": "1" | |
| } | |
| } | |
| ] |
Xet Storage Details
- Size:
- 105 kB
- Xet hash:
- a652ef45ffc97f41e8e13c29a59844577e5bd250628dd6a27f22efda1d33b4b9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.