#line 1 "main.cpp" #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #ifdef local #include #else #define dump(...) void(0); #endif #include #include #line 2 "/home/wa_haya_exe/CP_Library/C++/ds/DualSegmentTree.hpp" #pragma GCC diagnostic ignored "-Wreorder" #include #include template struct DualSegTree { private: using F = std::function; int sz, h; std::vector lazy; const T id; const F ap; inline void propagate(const int k) { if(lazy[k] != id) { lazy[2 * k] = ap(lazy[2 * k], lazy[k]); lazy[2 * k + 1] = ap(lazy[2 * k + 1], lazy[k]); lazy[k] = id; } } inline void thrust(const int k) { for(int i = h; i > 0; i--) { propagate(k >> i); } } public: DualSegTree(const int n, const F &ap, const T &id): ap(ap), id(id) { sz = 1; h = 0; while(sz < n) { sz <<= 1; h++; } lazy.assign(2 * sz, id); } void apply(int a, int b, const T &x) { thrust(a += sz); thrust(b += sz - 1); for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) { if(l & 1) { lazy[l] = ap(lazy[l], x); l++; } if(r & 1) { r--; lazy[r] = ap(lazy[r], x); } } } inline T operator[](int k) { thrust(k += sz); return lazy[k]; } }; /** * @brief 双対セグ木 * @see https://ei1333.github.io/library/structure/segment-tree/dual-segment-tree.hpp */ #line 12 "main.cpp" namespace man { } int main() { std::cin.tie(nullptr) -> sync_with_stdio(false); using namespace std::ranges; using namespace std::views; int n, q; std::cin >> n >> q; DualSegTree seg(n, [](const int a, const int b) -> int { return a ^ b; }, 0); for(const auto &i: iota(0, n)) { int a; std::cin >> a; seg.apply(i, i + 1, a); } // for(const auto i: iota(0, n)) { // std::cout << seg[i] << " \n"[i + 1 == n]; // } for([[maybe_unused]] const auto _: iota(0, q)) { int l, r; std::cin >> l >> r; seg.apply(--l, r, 1); } for(const auto i: iota(0, n)) { std::cout << seg[i] << " \n"[i + 1 == n]; } }