Submission #716459

#TimeUsernameProblemLanguageResultExecution timeMemory
716459vjudge1XOR (IZhO12_xor)C++17
0 / 100
1 ms212 KiB
// #pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")  
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) (int)x.size()
#define bit(a, i) ((a>>i)&1)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll; 
typedef pair<int, int> pii;

const int P = 5;
const int K = 110;
const ll inf = 1e18;
const int mod = 1e9 + 7;
const int maxn = 3e5 + 100;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
const string C[] = {"NO\n", "YES\n"};   

int n, k;
int a[maxn];
int pref[maxn];

bool ok(int len){
    for(int i=len; i<=n; i++){
        if((pref[i]^pref[i-len]) >= k) return 1;
    }
    return 0;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for(int i=1; i<=n; i++){
        cin >> a[i];
        pref[i] = pref[i-1] ^ a[i];
    }
    int ans;
    for(int l=1, r=n; l<=r;){
        int mid = l+r>>1;
        if(!ok(mid)) r = mid - 1;
        else l = mid + 1, ans = mid;
    }
    for(int i=ans; i<=n; i++){
        if((pref[i]^pref[i-ans]) >= k){
            cout << i-ans+1 << " " << ans;
            return 0;
        }
    }
}    

Compilation message (stderr)

xor.cpp: In function 'int main()':
xor.cpp:46:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |         int mid = l+r>>1;
      |                   ~^~
xor.cpp:52:39: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |             cout << i-ans+1 << " " << ans;
      |                                       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...