# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
877152 |
2023-11-23T00:10:37 Z |
derar_alhamsh |
XOR (IZhO12_xor) |
C++14 |
|
1 ms |
360 KB |
#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,x;
cin>>n>>x;
int a[n];
trienode* root=new trienode();
for(int i=0;i<n;i++)
cin>>a[i];
int pre[n];
pre[0]=a[0];
for(int i=1;i<n;i++)
{
pre[i]=a[i];
pre[i]^=pre[i-1];
}
ll ans=-1,c=-1,ma=0,ind=-1;
root->add(0);
for(int i=0;i<n;i++)
{
cout<<root->GetMaxXor(pre[i])<<endl;
root->add(pre[i]);
}
for(int i=0; i<n; i++)
{
c++;
if(root->GetMaxXor(pre[i])>=x)
{
//cout<<root->GetMaxXor(pre[i])<<endl;
//cout<<c<<endl;
while(true)
{
if(i-c==0)
break;
if(root->GetMaxXor(pre[i]^a[i])>=x)
{
root->erase(pre[i-c]);
c--;
}
else
break;
}
ma=c;
ans=i+1;
}
root->add(pre[i-ma]);
}
cout<<ans-ma+1<<" "<<ma;
}
}
Compilation message
xor.cpp: In member function 'long long int trienode::low(int, std::bitset<32>&, std::bitset<32>&)':
xor.cpp:124:13: warning: unused variable 'cur' [-Wunused-variable]
124 | int cur = bt[i],less = 0;
| ^~~
xor.cpp: In function 'int main()':
xor.cpp:199:29: warning: unused variable 'ind' [-Wunused-variable]
199 | ll ans=-1,c=-1,ma=0,ind=-1;
| ^~~
xor.cpp: In function 'std::string getString()':
xor.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%s", c);
| ~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |