제출 #393081

#제출 시각아이디문제언어결과실행 시간메모리
393081SavicSXOR (IZhO12_xor)C++14
100 / 100
128 ms37812 KiB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 250005;
const int inf = 1e9 + 5;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

int n, X;
int niz[maxn];

int pref[maxn];

int idx = 0;
int najm[20 * maxn];
int lipa[20 * maxn][2];
void add(int A, int id) {

    int tr = 0;
    fb(mask,30,0) {
        int bt = 0;
        if(A & (1ll << mask))bt = 1;

        if(lipa[tr][bt] == 0)lipa[tr][bt] = ++idx;
        tr = lipa[tr][bt];

        najm[tr] = min(najm[tr], id);
    }

}

int kve(int A) {

    int tr = 0;
    int mn = inf;

    bool ok = 1;
    fb(mask,30,0) {
        int btA = 0;
        if(A & (1ll << mask))btA = 1;

        int btX = 0;
        if(X & (1ll << mask))btX = 1;

//		cout << "btA: " << btA << endl;
//		cout << "btX: " << btX << endl;

        if(btA == 1) {

            if(btX == 1) {
                if(lipa[tr][0] == 0) {
                    ok = 0;
                    break;
                }
                tr = lipa[tr][0];
            } else {

                int ntr = lipa[tr][0];
                if(ntr != 0) {
                    mn = min(mn, najm[ntr]);
                }

                if(lipa[tr][1] == 0) {
                    ok = 0;
                    break;
                }
                tr = lipa[tr][1];

            }

        } else {

            if(btX == 0) {

                int ntr = lipa[tr][1];
                if(ntr != 0) {
                    mn = min(mn, najm[ntr]);
                }

//				cout << "ovde: " << endl;
                if(lipa[tr][0] == 0) {
                    ok = 0;
                    break;
                }
                tr = lipa[tr][0];

            } else {
                if(lipa[tr][1] == 0) {
                    ok = 0;
                    break;
                }
                tr = lipa[tr][1];
            }

        }

//		cout << "------------------" << endl;
//		cout << endl;

    }

    if(ok)mn = min(mn, najm[tr]);

    return mn;

}

int main() 
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    cin >> n >> X;
    ff(i,1,n)cin >> niz[i];

    ff(i,1,n)pref[i] = pref[i - 1] ^ niz[i];
    memset(najm, inf, sizeof(najm));

    int rez = 0;
    int poz = 0;

    add(0, 0);
    ff(i,1,n) {
        // pref[i] ^ pref[j - 1] >= x

        int pos = kve(pref[i]);
        if(i - pos > rez) {
            rez = i - pos;
            poz = pos + 1;
        }
        add(pref[i], i);

    }

    cout << poz << " " << rez << endl;

    return 0;
}
/**

2 6
6 1

// probati bojenje sahovski ili slicno

**/


#Verdict Execution timeMemoryGrader output
Fetching results...