제출 #1358484

#제출 시각아이디문제언어결과실행 시간메모리
1358484vjudge1XOR (IZhO12_xor)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6 + 5, mod = 1e9 + 7;
int dx[] = {0, 0, -1, 1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};
class Binary_Trie
{
    struct Node
    {
        Node *bit[2];
        int freq[2], idx;
        Node()
        {
            memset(bit, 0, sizeof bit);
            memset(freq, 0, sizeof freq);
            idx = -1;
        }
    };

public:
    Node *root = new Node();
    Binary_Trie()
    {
        // insert(0);
    }
    void insert(int x, int j)
    {
        Node *cur = root;
        for (int i = 30; ~i; i--)
        {
            int on = (((1 << i) & x) > 0);
            if (cur->bit[on] == 0)
            {
                cur->bit[on] = new Node();
            }
            if (cur->idx == -1)
                cur->idx = j;
            cur->freq[on]++;
            cur = cur->bit[on];
        }
    }

    void remove(int x, int i, Node *cur)
    {
        if (!~i)
            return;
        int on = (((1 << i) & x) > 0);
        remove(x, i - 1, cur->bit[on]);
        cur->freq[on]--;
        if (cur->freq[on] == 0)
        {
            delete cur->bit[on];
            cur->bit[on] = 0;
        }
    }
    int mx_xor(int x)
    {
        int ret = 0;
        Node *cur = root;

        for (int i = 30; ~i; i--)
        {
            int on = (((1 << i) & x) > 0);
            if (cur->bit[on ^ 1] == 0)
            {
                cur = cur->bit[on];
            }
            else
            {
                cur = cur->bit[on ^ 1];
                ret |= (1 << i);
            }
        }
        return ret;
    }
    int query(int x)
    {
        int ret = 1e9;
        Node *cur = root;
        for (int i = 30; ~i; i--)
        {
            int on = (((1 << i) & x) > 0);
            if (cur->bit[on] == 0)
            {
                break;
            }
            if (cur->bit[on ^ 1] != 0)
            {
                ret = min(ret, cur->freq[on ^ 1]);
            }
            cur = cur->bit[on];
        }
        return ret;
    }
};

void solve()
{
    int n, x;
    cin >> n >> x;
    int a[n];
    Binary_Trie tr;
    int mx = 0, st = -1;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (i)
            a[i] ^= a[i - 1];
        int ans = tr.query(a[i] ^ x);
        if (ans != 1e9 && (!mx || (i - ans + 1) > mx))
            mx = i - ans + 1, st = ans;
        tr.insert(a[i], i);
    }
    cout << st + 1 << " " << mx;
}

int32_t main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    if (fopen("input.txt", "r"))
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
        cout << '\n';
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

xor.cpp: In function 'int32_t main()':
xor.cpp:123:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  123 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
xor.cpp:124:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  124 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...