QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370436#7937. Fast XORtingevirir#WA 217ms23932kbC++202.6kb2024-03-29 07:32:582024-03-29 07:32:59

Judging History

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

  • [2024-03-29 07:32:59]
  • 评测
  • 测评结果:WA
  • 用时:217ms
  • 内存:23932kb
  • [2024-03-29 07:32:58]
  • 提交

answer

#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;

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define cbug if(DEBUG) cout
#define setp(x) cout<<fixed<<setprecision(x)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
template<typename T>
using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
ostream& operator<<(ostream &out, ii x){ out<<"("<<x.F<<","<<x.S<<")"; return out; }
template<typename T> void amax(T &a, T b){ a=max(a,b); }
template<typename T> void amin(T &a, T b){ a=min(a,b); }
struct Hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}
	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

const ll INF = ll(1e18);
const int MOD = 998244353;
const bool DEBUG = 0;
const int MAXN = 100005;
const int LG = 21;

int main()
{
	cin.tie(0)->sync_with_stdio(0);

	ll n; cin>>n;
	vector<ll> a(n);
	forn(i,0,n) cin>>a[i];

	ll ans = 0;
	pbds<ll> s;
	for (int i = n - 1; i >= 0; i--)
	{
		ans += s.ook(a[i]);
		s.insert(a[i]);
	}

	ll sum = 0;
	int b = 0;
	while ((1 << b) != n) b++;
	bool c[n]{};
	vector<ll> a1;
	a1.reserve(n);
	for (int z = b - 1; z >= 0; z--)
	{
		ll len = (1 << (z + 1));
		ll inv = 0;
		for (int l = 0; l < n; l += len)
		{
			int r = l + len;
			forn(i, l, r)
			{
				c[i] = (a[i] & (1 << z)) > 0;
			}
			int c1 = 0;
			forn(i,l,r)
			{
				if (c[i]) c1++;
				else inv += c1;
			}
		}
		inv = min(inv, n * (len - 1) / 2 - inv);
		sum += inv;

		for (int l = 0; l < n; l += len)
		{
			int r = l + len;
			forn(i,l,r) if (!c[i]) a1.pb(a[i]);
			forn(i,l,r) if (c[i]) a1.pb(a[i]);
		}
		a = a1;
		a1.clear();
	}

	// if (ans <= sum + 1) cout << "Type 1\n";
	ans = min(ans, sum + 1);
	cout << ans << '\n';

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3824kb

input:

8
0 1 3 2 5 4 7 6

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

8
2 0 1 3 4 5 6 7

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 217ms
memory: 23932kb

input:

262144
47482 131703 90418 122675 166494 247529 196154 16950 66501 50357 246808 25929 10418 50538 26955 151884 63776 58023 20073 26544 74785 44064 41836 148543 87920 54172 3270 131495 130960 112122 167229 215767 77499 195004 21391 11039 168999 256346 109690 180904 172679 157200 78594 201857 52784 147...

output:

17145325034

result:

wrong answer 1st numbers differ - expected: '17137565829', found: '17145325034'