# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
875892 | derar_alhamsh | XOR (IZhO12_xor) | C++14 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define mxe(v) *max_element(v.begin(), v.end())
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend()
#define F first
#define S second
#define pi pair<ll,ll>
#define derar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
using namespace std;
const int N=400200;
const double PI=3.1415926535897932384626433;
const double eps = 1e-9;
string getString()
{
char c[(int)2e6];
//scanf(" %c",&a[i]);
scanf("%s", c);
return c;
//string x = getString();
}
///printf("%d\n",);
///scanf("%d",&);
///cout.precision(10);
///puts("")string
const int LOG = 32;
struct trienode {
trienode *child[2];
ll cnt, end;
trienode() {
memset(child, 0, sizeof child);
cnt = end = 0;
}
void add(int i, bitset<LOG> &bt) {
int cur = bt[i];
if (child[cur] == 0) child[cur] = new trienode();
child[cur]->cnt++;
if (i == 0) {
child[cur]->end++;
return;
}
child[cur]->add(i - 1, bt);
}
void add(ll num) {
cnt++;
bitset<LOG> bt(num);
add(LOG - 1, bt);
}
void erase(int i, bitset<LOG> &bt) {
int cur = bt[i];
child[cur]->cnt--;
if (i == 0) {
child[cur]->end--;
if (!child[cur]->cnt) {
delete child[cur];
child[cur] = 0;
}
return;
}
child[cur]->erase(i - 1, bt);
if (!child[cur]->cnt) {
delete child[cur];
child[cur] = 0;
}
}
void erase(ll num) {
bitset<LOG> bt(num);
if (!find(num))return;
cnt--;
erase(LOG - 1, bt);
}
bool find(int i, bitset<LOG> &bt) {
int cur = bt[i];
if (child[cur] == 0)return 0;
if (i == 0) {
return child[cur]->end > 0;
}
return child[cur]->find(i - 1, bt);
}
bool find(ll num) {
bitset<LOG> bt(num);
return find(LOG - 1, bt);
}
ll GetIndex(int i, bitset<LOG> &bt) {
int cur = bt[i];
if (child[cur] == 0) return 0;
int less = 0;
if (bt[i] && child[0] != 0)less += child[0]->cnt;
if (i == 0)return less;
return less + child[cur]->GetIndex(i - 1, bt);
}
ll GetIndex(ll num) {
bitset<LOG> bt(num);
if (!find(num))return -1;
return GetIndex(LOG - 1, bt);
}
ll GetMaxXor(int i, bitset<LOG> &bt) {
int cur = bt[i];
if (i == 0) {
if (child[!cur])return (1ll << i);
else return 0;
}
if (child[!cur])return (1ll << i) + child[!cur]->GetMaxXor(i - 1, bt);
else if (child[cur])return child[cur]->GetMaxXor(i - 1, bt);
else return 0;
}
ll GetMaxXor(ll num) {
bitset<LOG> bt(num);
return GetMaxXor(LOG - 1, bt);
}
ll low(int i, bitset<LOG> &bt,bitset<LOG> &bt1)
{
int cur = bt[i],less = 0;
if(i==-1)
return 0;
if (bt[i]==1 && bt1[i]==1)
{
if(child[1])
less+=child[1]->cnt;
if(child[0])
return less+=child[0]->low(i-1,bt,bt1);
return less;
}
else if(bt[i]==0 && bt1[i]==0)
{
if(child[0])
return child[0]->low(i-1,bt,bt1);
return 0;
}
else if(bt[i]==1 && bt1[i]==0)
{
if(child[1])
return less+=child[1]->low(i-1,bt,bt1);
return less;
}
else if(bt[i]==0 && bt1[i]==1)
{
if(child[0])
less+=child[0]->cnt;
if(child[1])
return less+=child[1]->low(i-1,bt,bt1);
return less;
}
}
ll low(ll num,ll k) {
bitset<LOG> bt(num);
bitset<LOG> bt1(k);
return low(LOG - 1, bt,bt1);
}
ll count(int i, bitset<LOG> &bt) {
int cur = bt[i];
if (child[cur] == 0)return 0;
if (i == 0) {
return child[cur]->cnt;
}
return child[cur]->count(i - 1, bt);
}
ll count(ll num) {
bitset<LOG> bt(num);
return count(LOG - 1, bt);
}
void clear() {
for (int i = 0; i < 2; i++)
if (child[i])
child[i]->clear(), delete child[i], child[i] = 0;
}
};
int main()
{
derar
int t=1;
//cin>>t;
while(t--)
{
ll n,k;
cin>>n>>k;
int a[n];
trienode* root=new trienode();
for(int i=0;i<n;i++)
cin>>a[i];
ll pre=0,ans=n+1,count=1,c=0;
root->add(0);
for(int i=n-1; i>0; i--)
{
pre^=a[i];
c+=root->low(pre,k);
if(c<count)
{
ans=i+1;
}
count+=n-i+1;
root->add(pre);
}
cout<<ans<<" ";
int ma=a[ans-1],x=ans;
for(int i=ans;i<n;i++)
{
ma^=a[i];
if(ma>=k)
x=i;
}
cout<<x;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |