Submission #531370

#TimeUsernameProblemLanguageResultExecution timeMemory
531370fcwXOR (IZhO12_xor)C++17
100 / 100
201 ms32436 KiB
#include <bits/stdc++.h> #define st first #define nd second using lint = int64_t; constexpr int mod = int(1e9) + 7; constexpr int inf = 0x3f3f3f3f; constexpr int ninf = 0xcfcfcfcf; constexpr lint linf = 0x3f3f3f3f3f3f3f3f; const long double pi = acosl(-1.0); // Returns -1 if a < b, 0 if a = b and 1 if a > b. int cmp_double(double a, double b = 0, double eps = 1e-9) { return a + eps > b ? b + eps > a ? 0 : 1 : -1; } using namespace std; const int K = 31; int main() { cin.tie(nullptr)->sync_with_stdio(false); vector<array<int, 2>>trie(1, {-1, -1}); vector<int>id(1, -1); int n, x; cin>>n>>x; vector<int>v(n+1); int mx = -1, ind = -1; int cnt = 0; for(int i=0;i<=n;i++){ if(i) cin>>v[i]; cnt ^= v[i]; if(i){ int cur = 0, mask = 0; for(int a=K;a>=0;a--){ int b = cnt>>a&1; if(trie[cur][!b] == -1){ cur = trie[cur][b]; } else{ mask |= (1<<a); cur = trie[cur][!b]; if(mask >= x){ //cout<<i+1<<" "<<mask<<" "<<id[cur]<<" "<<a<<"\n"; if(mx < i+1 - id[cur]){ mx = i+1 - id[cur]; ind = id[cur]; } } } } } int cur = 0; for(int a=K;a>=0;a--){ int b = cnt>>a&1; if(trie[cur][b] == -1){ trie[cur][b] = (int)trie.size(); trie.push_back({-1, -1}); id.push_back(i+1); } cur = trie[cur][b]; } } cout<<ind<<" "<<mx<<"\n"; return 0; } /* [ ]Leu o problema certo??? [ ]Ver se precisa de long long [ ]Viu o limite dos fors (é n? é m?) [ ]Tamanho do vetor, será que é 2e5 em vez de 1e5?? [ ]Testar sample [ ]Testar casos de borda [ ]1LL no 1LL << i [ ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?) */
#Verdict Execution timeMemoryGrader output
Fetching results...