QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#594983#7937. Fast XORtingMath4Life2020Compile Error//C++203.1kb2024-09-28 11:48:552024-09-28 11:48:57

Judging History

你现在查看的是最新测评结果

  • [2024-09-28 11:48:57]
  • 评测
  • [2024-09-28 11:48:55]
  • 提交

answer

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("popcnt,lzcnt,abm,bmi,bmi2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = int; using pii = pair<ll,ll>;


ll e2(ll x) {
	return (1LL<<x);
}

struct hashPii {
	ll operator()(const pii &p) const { return p.first + ((p.second+1)<<18); }
};

template <class K, class V>
using ht =
    gp_hash_table<K, V, hashPii, equal_to<K>, direct_mask_range_hashing<>,
                  linear_probe_fn<>,
                  hash_standard_resize_policy<hash_exponential_size_policy<>,
                                              hash_load_check_resize_trigger<>, true>>;

struct ntrie {
	//gp_hash_table<pair<ll,ll>,ll,hashPii> cnt;
	ht<pii,ll> cnt;
	vector<ll> nf,nr;
	vector<pii> vlist;
	ll E;
	ntrie(ll Ec) {
		E=Ec;
	}
	ntrie(ll x0, ll Ec) {
		cnt.resize(Ec+1);
		E=Ec;
		cnt[{0,-1}]=1;
		vlist.push_back({0,-1});
		for (ll j=0;j<E;j++) {
			ll xn = (x0>>(E-1-j))<<(E-1-j);
			cnt[{xn,j}]=1;
			vlist.push_back({xn,j});
			nf.push_back(0);
			nr.push_back(0);
		}
	}
	ll extract() {
		ll ans = 0;
		for (ll j=0;j<E;j++) {
			ans += min(nf[j],nr[j]);
		}
		return ans;
	}
	ll extractR() {
		ll ans = 0;
		for (ll j=0;j<E;j++) {
			ans += nr[j];
		}
		return ans;
	}
};

ntrie merge(ntrie t1, ntrie t2, ll E) {
	ntrie t0 = ntrie(E);
	for (ll i=0;i<E;i++) {
		t0.nr.push_back(t1.nr[i]+t2.nr[i]);
		t0.nf.push_back(t1.nf[i]+t2.nf[i]);
	}
	ll L1 = t1.vlist.size();
	ll L2 = t2.vlist.size();
	ll i1 = 0; ll i2 = 0;
	while (i1<L1 && i2<L2) {
		pii a = t1.vlist[i1]; pii b = t2.vlist[i2];
		if (a.first>b.first) {
			t0.vlist.push_back(b); i2++;
		} else if (a.first<b.first) {
			t0.vlist.push_back(a); i1++;
		} else {
			if (a.second>b.second) {
				t0.vlist.push_back(b); i2++;
			} else if (a.second<b.second) {
				t0.vlist.push_back(a); i1++;
			} else {
				t0.vlist.push_back(a); i1++; i2++;
			}
		}
	}
	while (i1<L1) {
		t0.vlist.push_back(t1.vlist[i1++]);
	}
	while (i2<L2) {
		t0.vlist.push_back(t2.vlist[i2++]);
	} 
	t0.cnt.resize(t0.vlist.size());
	for (pii p0: t0.vlist) {
		t0.cnt[p0]=0;
		if (t1.cnt.find(p0)!=t1.cnt.end()) {
			t0.cnt[p0]+=t1.cnt[p0];
		}
		if (t2.cnt.find(p0)!=t2.cnt.end()) {
			t0.cnt[p0]+=t2.cnt[p0];
		}
		ll x = p0.first; ll j = 1+p0.second;
		if (j>=E) {
			continue;
		}
		ll xl = x; ll xh = x+e2(E-1-j);
		t0.nf[j] += t1.cnt[{xl,j}]*t2.cnt[{xh,j}];
		t0.nr[j] += t1.cnt[{xh,j}]*t2.cnt[{xl,j}];
	}
	return t0;
}

ntrie build(vector<ll> a, ll E) {
	ll N = a.size();
	if (N==1) {
		return ntrie(a[0],E);
	}
	vector<ll> b,c;
	for (ll i=0;i<(N/2);i++) {
		b.push_back(a[i]);
	}
	for (ll i=(N/2);i<N;i++) {
		c.push_back(a[i]);
	}
	return merge(build(b,E),build(c,E),E);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll N; cin >> N;
	ll E = __builtin_ctz(N);
	vector<ll> a;
	for (ll i=0;i<N;i++) {
		ll x; cin >> x;
		a.push_back(x);
	}
	ntrie troot = build(a,E);
	ll ans = troot.extractR();
	ans = min(ans,1+troot.extract());
	cout << ans << "\n";
}

Details

In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:3:
/usr/include/c++/13/bits/allocator.h: In destructor ‘constexpr std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘constexpr std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~