QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#386871#7937. Fast XORtingcarbon111#WA 253ms23712kbC++201.6kb2024-04-11 20:53:112024-04-11 20:53:12

Judging History

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

  • [2024-04-11 20:53:12]
  • 评测
  • 测评结果:WA
  • 用时:253ms
  • 内存:23712kb
  • [2024-04-11 20:53:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define FINISH cerr << "FINISH" << endl;
#define debug(x) cerr << #x << " == " << x << endl
#define el '\n'
#define fir first
#define sec second
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
const int N = 400020;
int t[N], n, tot;
int lowbit(int x)
{
	return x & (-x);
}
void add(int x, int val)
{
	while (x <= n) {
		t[x] += val;
		x += lowbit(x);
	}
}
int getsum(int x)
{
	int rr = 0;
	while (x >= 1) {
		rr += t[x];
		x -= lowbit(x);
	}
	return rr;
}
ll calc(vector<int>& a)
{
	for (int i = 0; i <= n; i++)
		t[i] = 0;
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		add(a[i] + 1, 1);
		sum += getsum(a[i]);
	}
	return n * (n - 1) / 2 - sum;
}
void getans(int now, vector<int>& a)
{
	if (now == 0)
		return;
	vector<int> b = a;
	for (int i = 1; i <= n; i++) {
		b[i] ^= now;
	}
	ll sum1 = calc(a);
	ll sum2 = calc(b);
	/*debug(now);
	for (int i = 1; i <= n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
	for (int i = 1; i <= n; i++) {
		cout << b[i] << " ";
	}
	cout << endl;
	cout << sum1 << " " << sum2 << endl;*/
	if (sum1 > sum2 + 1) {
		a = b;
	}
	getans(now / 2, a);
}
void solve()
{
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	ll ans = calc(a);
	getans(n / 2, a);
	ans = min(ans, calc(a) + 1);
	cout << ans << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3568kb

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: 3612kb

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: 253ms
memory: 23712kb

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:

-17222172539

result:

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