Submission #845024


Source Code Expand

Copy
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

struct FenwickTree {
	typedef int T;
	vector<T> v;
	FenwickTree(int n) : v(n, 0) {}
	void add(int i, T x) {
		for(; i < (int)v.size(); i |= i + 1) v[i] += x;
	}
	T sum(int i) {	//[0, i)
		T r = 0;
		for(-- i; i >= 0; i = (i & (i + 1)) - 1) r += v[i];
		return r;
	}
	T sum(int left, int right) {	//[left, right)
		return sum(right) - sum(left);
	}
};

long long inversionNumber(int x[], int n) {
	int *c = new int[n];
	memcpy(c, x, sizeof(*x) * n);
	sort(c, c + n);
	int m = unique(c, c + n) - c;
	FenwickTree ft(m);
	long long res = 0;
	for(int i = n - 1; i >= 0; i --) {
		int idx = lower_bound(c, c + m, x[i]) - c;
		res += ft.sum(idx);
		ft.add(idx, 1);
	}
	delete[] c;
	return res;
}

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> A(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &A[i]);
		vector<int> B[2];
		rep(i, N)
			B[i % 2].push_back(A[i]);
		rep(k, 2)
			sort(B[k].begin(), B[k].end());
		vector<int> C;
		rep(i, N)
			C.push_back(B[i % 2][i / 2]);
		ll ans = inversionNumber(C.data(), C.size());
		printf("%lld\n", ans);
	}
	return 0;
}

Submission Info

Submission Time
Task C - BBuBBBlesort!
User anta
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1714 Byte
Status WA
Exec Time 59 ms
Memory 2424 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:49:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &A[i]);
                      ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 2
AC × 17
WA × 7
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt WA 59 ms 2424 KB
02.txt WA 58 ms 2424 KB
03.txt WA 58 ms 2424 KB
04.txt WA 58 ms 2424 KB
05.txt WA 54 ms 2424 KB
06.txt WA 54 ms 2424 KB
07.txt WA 55 ms 2424 KB
08.txt AC 43 ms 2424 KB
09.txt AC 43 ms 2424 KB
10.txt AC 42 ms 2424 KB
11.txt AC 43 ms 2424 KB
12.txt AC 43 ms 2424 KB
13.txt AC 43 ms 2424 KB
14.txt AC 51 ms 2424 KB
15.txt AC 51 ms 2424 KB
16.txt AC 51 ms 2424 KB
17.txt AC 51 ms 2424 KB
18.txt AC 4 ms 256 KB
19.txt AC 4 ms 256 KB
20.txt AC 4 ms 256 KB
21.txt AC 4 ms 256 KB
22.txt AC 4 ms 256 KB
s1.txt AC 4 ms 256 KB
s2.txt AC 4 ms 256 KB