Submission #729341

# Submission time Handle Problem Language Result Execution time Memory
729341 2023-04-23T21:42:35 Z finn__ XOR (IZhO12_xor) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

constexpr size_t L = 30;

struct Trie
{
    Trie *c[2];
    unsigned subtree_min;

    Trie() { c[0] = c[1] = 0, subtree_min = UINT_MAX; }

    void insert(unsigned x, unsigned j, unsigned i = 0)
    {
        if (i == L)
        {
            subtree_min = j;
            return;
        }
        bool z = x & (1 << (L - i - 1));
        if (!c[z])
            c[z] = new Trie();
        c[z]->insert(x, j, i + 1);
        subtree_min = min(c[0] ? c[0]->subtree_min : UINT_MAX,
                          c[1] ? c[1]->subtree_min : UINT_MAX);
    }

    unsigned get_earliest_ge(unsigned x, unsigned y, unsigned i = 0)
    {
        if (i == L)
            return subtree_min;
        bool z = x & (1 << (L - i - 1));
        if (y & (1 << (L - i - 1)))
        {
            return c[!z] ? c[!z]->get_earliest_ge(x, y, i + 1) : UINT_MAX;
        }
        else
        {
            return min(c[z] ? c[z]->get_earliest_ge(x, y, i + 1) : UINT_MAX,
                       c[!z] ? c[!z]->subtree_min : UINT_MAX);
        }
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    size_t n;
    unsigned y;
    cin >> n >> y;
    unsigned pxor = 0, i = 0, k = 0;
    Trie t;
    t.insert(0, 0);
    for (size_t j = 1; j <= n; ++j)
    {
        unsigned a;
        cin >> a;
        pxor ^= a;
        unsigned h = t.get_earliest_ge(pxor, y);
        if (h != UINT_MAX && j - h > k)
            k = j - h, i = h;
        t.insert(pxor, j);
    }

    cout << i + 1 << ' ' << k << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -