Submission #1066290

#TimeUsernameProblemLanguageResultExecution timeMemory
1066290shohag_shadowXOR (IZhO12_xor)C++14
0 / 100
1 ms344 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long int #define endl '\n' typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key #define all(v) v.begin(), v.end() #define pb push_back // #define mp make_pair #define fi first // #define se second // #define yes cout << "YES" << endl // #define no cout << "NO" << endl // #define M 1000000007 // 1e9+7 #define gcd(a, b) __gcd(a, b) // #define lcm(a, b) a *b / gcd(a, b) // #define memz(a) memset(a, 0, sizeof(a)) // #define memn(a) memset(a, -1, sizeof(a)) // struct node { node *links[2]; ll count=0; }; node *root ; void insert(ll val) { node *ptr=root; for(int i=30;i>=0;i--) { if((1ll<<i)&val) { if(ptr->links[1]==NULL) { ptr->links[1]=new node(); } ptr=ptr->links[1]; } else { if(ptr->links[0]==NULL) { ptr->links[0]=new node(); } ptr=ptr->links[0]; } ptr->count++; } } ll query(ll k,ll pre) { ll ans=0; node *ptr=root; int i; for( i=30;i>=0;i--) { if((1ll<<i)&pre) { if((1ll<<i)&k) { if(ptr->links[0]==NULL) { break; } ptr=ptr->links[0]; } else { if(ptr->links[0]!=NULL) { ans+=ptr->links[0]->count; } if(ptr->links[1]==NULL) { break; } ptr=ptr->links[1]; } } else { if((1LL<<i)&k) { if(ptr->links[1]==NULL) { break; } ptr=ptr->links[1]; } else { if(ptr->links[1]!=NULL) { ans+=ptr->links[1]->count; } if(ptr->links[0]==NULL) { break; } ptr=ptr->links[0]; } } } if(i<0)ans+=ptr->count; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n,k; cin>>n>>k; root=new node(); ll pre=0; ll ans=0; insert(0); for(int i=0;i<n;i++) { ll t; cin>>t; pre=(pre^t); ans+=query(k,pre); insert(pre); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...