Submission #875892

#TimeUsernameProblemLanguageResultExecution timeMemory
875892derar_alhamshXOR (IZhO12_xor)C++14
0 / 100
1 ms348 KiB
#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)

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 '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);
      |     ~~~~~^~~~~~~~~
xor.cpp: In member function 'long long int trienode::low(int, std::bitset<32>&, std::bitset<32>&)':
xor.cpp:155:5: warning: control reaches end of non-void function [-Wreturn-type]
  155 |     }
      |     ^
#Verdict Execution timeMemoryGrader output
Fetching results...