QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#785228#9614. 分治peaneval_kala100 ✓2363ms125628kbC++2313.2kb2024-11-26 17:14:272024-11-26 17:14:27

Judging History

你现在查看的是最新测评结果

  • [2024-11-26 17:14:27]
  • 评测
  • 测评结果:100
  • 用时:2363ms
  • 内存:125628kb
  • [2024-11-26 17:14:27]
  • 提交

answer

#pragma GCC optimize(3, "unroll-loops", "no-stack-protector")
#define atsum(l, r) accumulate(l, r, 0)
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 0x3f3f3f3f;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
inline void chkmin(T &x, T y) {
    x = min(x, y);
}
template <typename T>
inline void chkmax(T &x, T y) {
    x = max(x, y);
}
namespace FastIO {
// ------------------------------
#define IN_HAS_NEG
#define OUT_HAS_NEG
#define CHK_EOF
#define DISABLE_MMAP
// ------------------------------
#if __cplusplus < 201400
#error Please use C++14 or higher.
#endif
#if __cplusplus > 201700
#define INLINE_V inline
#else
#define INLINE_V
#endif
#if (defined(LOCAL) || defined(_WIN32)) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifndef DISABLE_MMAP
#include <sys/mman.h>
#endif
#ifdef LOCAL
inline char gc() { return getchar(); }
inline void pc(char c) { putchar(c); }
#else
#ifdef DISABLE_MMAP
INLINE_V constexpr int _READ_SIZE = 1 << 18;
INLINE_V static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr,
                                               *_read_ptr_end = nullptr;
inline char gc() {
    if (__builtin_expect(_read_ptr == _read_ptr_end, false)) {
        _read_ptr = _read_buffer;
        _read_ptr_end =
            _read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin);
#ifdef CHK_EOF
        if (__builtin_expect(_read_ptr == _read_ptr_end, false)) return EOF;
#endif
    }
    return *_read_ptr++;
}
#else
INLINE_V static const char *_read_ptr =
    (const char *)mmap(nullptr, INT_MAX, 1, 2, 0, 0);
inline char gc() { return *_read_ptr++; }
#endif
INLINE_V constexpr int _WRITE_SIZE = 1 << 18;
INLINE_V static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer;
inline void pc(char c) {
    *_write_ptr++ = c;
    if (__builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false)) {
        fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout);
        _write_ptr = _write_buffer;
    }
}
INLINE_V struct _auto_flush {
    ~_auto_flush() {
        fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout);
    }
} _auto_flush;
#endif
#ifdef CHK_EOF
inline bool _isdigit(char c) { return (c & 16) && c != EOF; }
inline bool _isgraph(char c) { return c > 32 && c != EOF; }
#else
inline bool _isdigit(char c) { return c & 16; }
inline bool _isgraph(char c) { return c > 32; }
#endif
template <class T>
INLINE_V constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <class T>
INLINE_V constexpr bool _is_signed = numeric_limits<T>::is_signed;
template <class T>
INLINE_V constexpr bool _is_unsigned = _is_integer<T> && !_is_signed<T>;
template <>
INLINE_V constexpr bool _is_integer<__int128> = true;
template <>
INLINE_V constexpr bool _is_integer<__uint128_t> = true;
template <>
INLINE_V constexpr bool _is_signed<__int128> = true;
template <>
INLINE_V constexpr bool _is_unsigned<__uint128_t> = true;
#undef INLINE_V
inline void read(char &c) {
    do c = gc();
    while (!_isgraph(c));
}
inline void read_cstr(char *s) {
    char c = gc();
    while (!_isgraph(c)) c = gc();
    while (_isgraph(c)) *s++ = c, c = gc();
    *s = 0;
}
inline void read(string &s) {
    char c = gc();
    s.clear();
    while (!_isgraph(c)) c = gc();
    while (_isgraph(c)) s.push_back(c), c = gc();
}
#ifdef IN_HAS_NEG
template <class T, enable_if_t<_is_signed<T>, int> = 0>
inline void read(T &x) {
    char c = gc();
    bool f = true;
    x = 0;
    while (!_isdigit(c)) {
        if (c == 45) f = false;
        c = gc();
    }
    if (f)
        while (_isdigit(c)) x = x * 10 + (c & 15), c = gc();
    else
        while (_isdigit(c)) x = x * 10 - (c & 15), c = gc();
}
template <class T, enable_if_t<_is_unsigned<T>, int> = 0>
#else
template <class T, enable_if_t<_is_integer<T>, int> = 0>
#endif
inline void read(T &x) {
    char c = gc();
    while (!_isdigit(c)) c = gc();
    x = 0;
    while (_isdigit(c)) x = x * 10 + (c & 15), c = gc();
}
inline void write(char c) { pc(c); }
inline void write_cstr(const char *s) {
    while (*s) pc(*s++);
}
inline void write(const string &s) {
    for (char c : s) pc(c);
}
#ifdef OUT_HAS_NEG
template <class T, enable_if_t<_is_signed<T>, int> = 0>
inline void write(T x) {
    char buffer[numeric_limits<T>::digits10 + 1];
    int digits = 0;
    if (x >= 0) do
            buffer[digits++] = (x % 10) | 48, x /= 10;
        while (x);
    else {
        pc(45);
        do buffer[digits++] = -(x % 10) | 48, x /= 10;
        while (x);
    }
    while (digits) pc(buffer[--digits]);
}
template <class T, enable_if_t<_is_unsigned<T>, int> = 0>
#else
template <class T, enable_if_t<_is_integer<T>, int> = 0>
#endif
inline void write(T x) {
    char buffer[numeric_limits<T>::digits10 + 1];
    int digits = 0;
    do buffer[digits++] = (x % 10) | 48, x /= 10;
    while (x);
    while (digits) pc(buffer[--digits]);
}
template <int N>
struct _tuple_io_helper {
    template <class... T>
    static inline void _read(tuple<T...> &x) {
        _tuple_io_helper<N - 1>::_read(x), read(get<N - 1>(x));
    }
    template <class... T>
    static inline void _write(const tuple<T...> &x) {
        _tuple_io_helper<N - 1>::_write(x), pc(32), write(get<N - 1>(x));
    }
};
template <>
struct _tuple_io_helper<1> {
    template <class... T>
    static inline void _read(tuple<T...> &x) {
        read(get<0>(x));
    }
    template <class... T>
    static inline void _write(const tuple<T...> &x) {
        write(get<0>(x));
    }
};
template <class... T>
inline void read(tuple<T...> &x) {
    _tuple_io_helper<sizeof...(T)>::_read(x);
}
template <class... T>
inline void write(const tuple<T...> &x) {
    _tuple_io_helper<sizeof...(T)>::_write(x);
}
template <class T1, class T2>
inline void read(pair<T1, T2> &x) {
    read(x.first), read(x.second);
}
template <class T1, class T2>
inline void write(const pair<T1, T2> &x) {
    write(x.first), pc(32), write(x.second);
}
template <class T1, class... T2>
inline void read(T1 &x, T2 &...y) {
    read(x), read(y...);
}
template <class... T>
inline void read_cstr(char *x, T *...y) {
    read_cstr(x), read_cstr(y...);
}
template <class T1, class... T2>
inline void write(const T1 &x, const T2 &...y) {
    write(x), write(y...);
}
template <class... T>
inline void write_cstr(const char *x, const T *...y) {
    write_cstr(x), write_cstr(y...);
}
template <class T>
inline void print(const T &x) {
    write(x);
}
inline void print_cstr(const char *x) { write_cstr(x); }
template <class T1, class... T2>
inline void print(const T1 &x, const T2 &...y) {
    print(x), pc(32), print(y...);
}
template <class... T>
inline void print_cstr(const char *x, const T *...y) {
    print_cstr(x), pc(32), print_cstr(y...);
}
inline void println() { pc(10); }
inline void println_cstr() { pc(10); }
template <class... T>
inline void println(const T &...x) {
    print(x...), pc(10);
}
template <class... T>
inline void println_cstr(const T *...x) {
    print_cstr(x...), pc(10);
}
}  // namespace FastIO
using namespace FastIO;
template <typename T>
inline void clear(T &x) {
    T y;
    swap(x, y);
}
template <uint32_t mod = 998244353>
class Modint {
   private:
    static constexpr uint32_t get_r() {
        uint32_t ret = mod;
        for (int i = 0; i < 4; i++) ret *= 2 - mod * ret;
        return ret;
    }
    static constexpr uint32_t r = get_r();
    static constexpr uint32_t n2 = -uint64_t(mod) % mod;
    static_assert(r * mod == 1 && mod < (1 << 30) && mod & 1);
    uint32_t data;

   public:
    constexpr Modint() : data(0) {}
    template <class int_t>
    constexpr Modint(const int_t x)
        : data(reduce(
              uint64_t((sizeof(int_t) < sizeof(uint32_t) ? x : x % int_t(mod)) +
                       mod) *
              n2)){};
    static constexpr uint32_t reduce(const uint64_t x) {
        return (x + uint64_t(uint32_t(x) * (-r)) * mod) >> 32;
    }
    constexpr Modint &operator+=(const Modint &r) {
        if (int32_t(data += r.data - 2 * mod) < 0) {
            data += 2 * mod;
        }
        return *this;
    }
    constexpr Modint &operator-=(const Modint &r) {
        if (int32_t(data -= r.data) < 0) {
            data += 2 * mod;
        }
        return *this;
    }
    constexpr Modint &operator*=(const Modint &r) {
        return data = reduce((uint64_t)data * r.data), *this;
    }
    constexpr Modint &operator/=(const Modint &r) { return *this *= r.inv(); }
    constexpr friend Modint operator+(Modint l, const Modint &r) {
        return l += r;
    }
    constexpr friend Modint operator-(Modint l, const Modint &r) {
        return l -= r;
    }
    constexpr friend Modint operator*(Modint l, const Modint &r) {
        return l *= r;
    }
    constexpr friend Modint operator/(Modint l, const Modint &r) {
        return l /= r;
    }
    constexpr friend bool operator==(Modint l, const Modint &r) {
        return l.value() == r.value();
    }
    constexpr Modint operator-() const { return Modint() - Modint(*this); }
    template <class int_t>
    constexpr Modint pow(int_t r) const {
        Modint res(1), w(*this);
        for (; r; r >>= 1, w *= w)
            if (r & 1) res *= w;
        return res;
    }
    constexpr Modint inv() const { return pow(mod - 2); }
    constexpr uint32_t value() const {
        uint32_t res = reduce(data);
        return res >= mod ? res - mod : res;
    }
};
using modint = Modint<>;
namespace cmaths {
const int FACMAX = 1e7 + 10;
modint fac[FACMAX], ifac[FACMAX], inv[FACMAX];
inline void initfac(int n) {
    fac[0] = 1;
    for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i;
}
inline void initifac(int n) {
    ifac[n] = fac[n].inv();
    for (int i = n - 1; ~i; i--) ifac[i] = ifac[i + 1] * (i + 1);
}
inline modint C(int a, int b) {
    return a < b ? 0 : fac[a] * ifac[b] * ifac[a - b];
}
inline modint A(int a, int b) { return a < b ? 0 : fac[a] * ifac[a - b]; }
inline void getInv(int k) {
    inv[1] = 1;
    for (int i = 2; i <= k; ++i) inv[i] = ifac[i] * fac[i - 1];
}
inline void initall(int n = FACMAX - 2) { initfac(n), initifac(n), getInv(n); }
};  // namespace cmaths
using namespace cmaths;
int n;
inline modint solve(int len) {
    modint ans = 0;
    for (int k = 1; k <= len; k++) {
        for (int j = 1; j * k <= len; j++) {
            if (len - j * k - j >= 0)
                ans += C(len - j * k, j) * modint(2).pow(len - j * k - j) *
                       modint(-1).pow(j - 1);
            if (len - j * k - (j - 1) >= 0)
                ans += C(len - j * k, j - 1) *
                       modint(2).pow(len - j * k - (j - 1)) *
                       modint(-1).pow(j - 1);
        }
    }
    return ans;
}
const int N = 2e5 + 10;
modint pw[N];
bool o1;
modint f[N], g[N];
int sn, px[N], py[N], pz[N], cnt;
inline modint calc(int x, int y, int z) {
    chkmax(z, y);
    ++cnt;
    px[cnt] = x, py[cnt] = y, pz[cnt] = z;
    modint res = z * modint(2).pow(x);
    return res;
}
bool o2;
string lim;
int main() {
    cerr << (&o2 - &o1) / 1048576. << endl;
    initall();
    pw[0] = 1;
    string str;
    read(str);
    modint mn = 0;
    for (char v : str) mn = mn * 2 + (v - '0');
    modint ans = solve(str.size() - 1);
    lim = str, lim.erase(lim.begin());
    int n = lim.size();
    sn = sqrtl(n);
    for (int i = 1; i <= n + 1; i++) pw[i] = pw[i - 1] * 2;
    int cur = 1, mx = 1;
    for (int i = n; i; i--)
        if (lim[n - i] == '0')
            cur++;
        else
            ans += calc(i - 1, cur + 1, mx), mx = max(mx, cur), cur = 0;
    for (int i = 1; i <= sn; i++) {
        memset(f, 0, sizeof(f));
        memset(g, 0, sizeof(g));
        for (int j = 1; j <= n; j++) {
            if (j >= i) f[j] = f[j - i];
            if (j >= i * 2) f[j] += C(j - i, i) * pw[j - i - i] * (i & 1 ? 1 : -1);
        }
        for (int j = 1; j <= n; j++) {
            if (j >= i) g[j] = g[j - i];
            if (j >= i * 2 - 1) g[j] += C(j - i, i - 1) * pw[j - i - (i - 1)] * (i & 1 ? 1 : -1);
        }
        for (int j = 1; j <= cnt; j++) {
            int cx = px[j] - max(pz[j], sn) * i;
            if (cx >= 0) ans += f[cx];
            if (cx + py[j] >= 0) ans += g[cx + py[j]];
        }
    }
    for (int i = 1; i <= sn; i++) {
        memset(f, 0, sizeof(f));
        for (int j = 1; j <= n; j++) {
            f[j] = 2 * f[j - 1];
            if (j >= (i + 1)) f[j] -= f[j - i - 1];
            if (j >= i + 1) f[j] += C(j - i - 1, 0) * pw[j - i - 1];
        }
        for (int j = 1; j <= cnt; j++) if (pz[j] < i && i <= px[j] + py[j]) ans += f[px[j]];
    }
    for (int i = 1; i <= sn; i++) {
        memset(f, 0, sizeof(f));
        for (int j = 1; j <= n + 1; j++) {
            f[j] = 2 * f[j - 1];
            if (j >= (i + 1)) f[j] -= f[j - i - 1];
            if (j == i) f[j] += (j - i - 1 == -1 ? 1 : 0) * pw[j - i];
        }
        for (int j = 1; j <= cnt; j++) if (pz[j] < i && i <= px[j] + py[j]) ans += f[px[j] + py[j]];
    }
    println((ans + mn).value());
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 81ms
memory: 123696kb

input:

110

output:

15

result:

ok 1 number(s): "15"

Test #2:

score: 10
Accepted
time: 83ms
memory: 124988kb

input:

101

output:

12

result:

ok 1 number(s): "12"

Subtask #2:

score: 10
Accepted

Dependency #1:

100%
Accepted

Test #3:

score: 10
Accepted
time: 43ms
memory: 125328kb

input:

111110

output:

198

result:

ok 1 number(s): "198"

Test #4:

score: 10
Accepted
time: 78ms
memory: 125120kb

input:

1001001

output:

253

result:

ok 1 number(s): "253"

Subtask #3:

score: 20
Accepted

Dependency #2:

100%
Accepted

Test #5:

score: 20
Accepted
time: 74ms
memory: 123944kb

input:

10100011000100111

output:

386882

result:

ok 1 number(s): "386882"

Test #6:

score: 20
Accepted
time: 57ms
memory: 124644kb

input:

111010011111010110

output:

1107742

result:

ok 1 number(s): "1107742"

Subtask #4:

score: 5
Accepted

Test #7:

score: 5
Accepted
time: 82ms
memory: 123452kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

output:

412796008

result:

ok 1 number(s): "412796008"

Test #8:

score: 5
Accepted
time: 83ms
memory: 123752kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

output:

818656648

result:

ok 1 number(s): "818656648"

Subtask #5:

score: 5
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #9:

score: 5
Accepted
time: 78ms
memory: 125216kb

input:

10000000100000010010011110111101101110000000000001100000011000111111010011010101010000101001110110010001100110000110111101000101001111101111001010001001011101011111010000100010111100110000001101111

output:

703266161

result:

ok 1 number(s): "703266161"

Test #10:

score: 5
Accepted
time: 83ms
memory: 125160kb

input:

110100000100001000101000010010101000110111101010110000101001001100100111000011100101110110010000001111010011101001111110110010001110011101001111010101100100010011101010101111111111010110001100100110

output:

330527406

result:

ok 1 number(s): "330527406"

Subtask #6:

score: 5
Accepted

Dependency #4:

100%
Accepted

Test #11:

score: 5
Accepted
time: 89ms
memory: 123408kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

340672883

result:

ok 1 number(s): "340672883"

Test #12:

score: 5
Accepted
time: 77ms
memory: 125296kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

555946758

result:

ok 1 number(s): "555946758"

Subtask #7:

score: 10
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #13:

score: 10
Accepted
time: 84ms
memory: 125320kb

input:

110011100110101000000110101010111111001101101011010110100100110010111110110110000111011001110000101111110111011111000110001011011011101100001100100011010010111111010110010000101001001000100001100100000001000111110100000101001011100001100011011110110101101111110011100111001010001010001111001110111100...

output:

324123594

result:

ok 1 number(s): "324123594"

Test #14:

score: 10
Accepted
time: 88ms
memory: 123868kb

input:

110100110100110110001011100000011010000010000101100100001101100100110000101000111001111100001110001001101010110010111101000100111010001011001110101010001101111010000011000010110011000011100101110100000001011100111000101111010100001101011010100101110000010001101001000100111001101101110000101101011011...

output:

209285599

result:

ok 1 number(s): "209285599"

Subtask #8:

score: 10
Accepted

Dependency #6:

100%
Accepted

Test #15:

score: 10
Accepted
time: 1060ms
memory: 125492kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

468567454

result:

ok 1 number(s): "468567454"

Test #16:

score: 10
Accepted
time: 2089ms
memory: 125180kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

12752860

result:

ok 1 number(s): "12752860"

Subtask #9:

score: 25
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Test #17:

score: 25
Accepted
time: 2363ms
memory: 125628kb

input:

101100010100101011010110001111101101001010000111001111000100110110010111101100011011011111010110000000011110000010100110111110110001101001101101001110101110011000010100100101000011000010000101011001011011000000100111011110100010000100001101011110100101110000100011000101100000111111100110000111010000...

output:

711712397

result:

ok 1 number(s): "711712397"

Test #18:

score: 25
Accepted
time: 2355ms
memory: 125616kb

input:

110101110100100010101100000110000110101101111100110011100111111110000101111001101001111000110111100111110111010001000010111111110000001001011110101110001011010010010011101000110110000110110101000100111000100110101111011101111101000010000101001001000010011011000011001100111111011000111000010000100111...

output:

171668334

result:

ok 1 number(s): "171668334"

Test #19:

score: 25
Accepted
time: 2177ms
memory: 124228kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

397846555

result:

ok 1 number(s): "397846555"

Test #20:

score: 25
Accepted
time: 2271ms
memory: 125232kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

592103795

result:

ok 1 number(s): "592103795"

Extra Test:

score: 0
Extra Test Passed