Submission #50389847


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/modint>
#include <atcoder/lazysegtree>

namespace {
    using ModInt [[maybe_unused]] = atcoder::modint998244353;
    using Num [[maybe_unused]] = long long int;
    using Vec [[maybe_unused]] = std::vector<Num>;
    using Set [[maybe_unused]] = std::set<Num>;
    using Mset [[maybe_unused]] = std::multiset<Num>;
    using Edges [[maybe_unused]] = std::vector<std::vector<Num>>;

    template<typename T>
    using Q [[maybe_unused]] = std::queue<T>;

    template<typename T>
    using PQ [[maybe_unused]] = std::priority_queue<T, std::vector<T>, std::greater<T>>;
}

struct Node {
    Num left {0};
    Num right {0};
    Num width {0};
    bool good {true};

    Node(void) = default;

    explicit Node(Num digit) {
        left = digit;
        right = digit;
        width = 1;
        good = true;
    }

    Node flip() const {
        Node result = *this;
        result.left = 1 - left;
        result.right = 1 - right;
        return result;
    }

    Node merge(const Node& rhs) const {
        if (width == 0) {
            return rhs;
        }

        if (rhs.width == 0) {
            return *this;
        }

        Node result;
        result.left = left;
        result.right = rhs.right;
        result.width = width + rhs.width;
        result.good = good && rhs.good && (right != rhs.left);
        return result;
    }
};

Node func_operate(Node a, Node b) {
    return a.merge(b);
}

Node func_unit() {
    return Node();
}

Node func_map(Num a, Node b) {
    if (a != 0) {
        return b.flip();
    } else {
        return b;
    }
}

Num func_compose(Num a, Num b) {
    return a ^ b;
}

Num func_id() {
    return 0;
}

void solve(std::istream& is, std::ostream& os) {
    Num n, q;
    std::string s;
    is >> n >> q >> s;

    atcoder::lazy_segtree<Node, func_operate, func_unit, Num, func_map, func_compose, func_id> tree(n);
    for(Num i{0}; i<n; ++i) {
        Num d = s.at(i) - '0';
        Node nd(d);
        tree.set(i, nd);
    }

    while(q-- > 0) {
        Num cmd, l, r;
        is >> cmd >> l >> r;
        --l;

        if (cmd == 1) {
            tree.apply(l, r, 1);
        } else {
            const auto node = tree.prod(l, r);
            if (node.good) {
                os << "Yes\n";
            } else {
                os << "No\n";
            }
        }
    }
}

int main(void) {
    solve(std::cin, std::cout);
    return 0;
}

Submission Info

Submission Time
Task E - Alternating String
User zettsut
Language C++ 20 (gcc 12.2)
Score 450
Code Size 2556 Byte
Status AC
Exec Time 819 ms
Memory 56324 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 2
AC × 42
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3548 KiB
example_01.txt AC 1 ms 3464 KiB
hand_00.txt AC 582 ms 56180 KiB
hand_01.txt AC 620 ms 56176 KiB
hand_02.txt AC 699 ms 56252 KiB
hand_03.txt AC 464 ms 56228 KiB
hand_04.txt AC 599 ms 3492 KiB
hand_05.txt AC 464 ms 56180 KiB
hand_06.txt AC 635 ms 56124 KiB
hand_07.txt AC 462 ms 56176 KiB
hand_08.txt AC 463 ms 56316 KiB
hand_09.txt AC 462 ms 56232 KiB
random_00.txt AC 746 ms 56320 KiB
random_01.txt AC 810 ms 56260 KiB
random_02.txt AC 768 ms 56152 KiB
random_03.txt AC 789 ms 56252 KiB
random_04.txt AC 112 ms 56148 KiB
random_05.txt AC 111 ms 56084 KiB
random_06.txt AC 705 ms 56128 KiB
random_07.txt AC 819 ms 56236 KiB
random_08.txt AC 728 ms 56320 KiB
random_09.txt AC 795 ms 56176 KiB
random_10.txt AC 110 ms 56172 KiB
random_11.txt AC 110 ms 56228 KiB
random_12.txt AC 702 ms 56228 KiB
random_13.txt AC 814 ms 56128 KiB
random_14.txt AC 733 ms 56260 KiB
random_15.txt AC 806 ms 56324 KiB
random_16.txt AC 109 ms 56232 KiB
random_17.txt AC 110 ms 56320 KiB
random_18.txt AC 770 ms 56188 KiB
random_19.txt AC 817 ms 56232 KiB
random_20.txt AC 784 ms 56172 KiB
random_21.txt AC 784 ms 56180 KiB
random_22.txt AC 105 ms 56228 KiB
random_23.txt AC 106 ms 56160 KiB
random_24.txt AC 757 ms 56184 KiB
random_25.txt AC 808 ms 56184 KiB
random_26.txt AC 762 ms 56172 KiB
random_27.txt AC 779 ms 56148 KiB
random_28.txt AC 105 ms 56172 KiB
random_29.txt AC 105 ms 56220 KiB