結果

問題 No.2029 Swap Min Max Min
ユーザー olpheolphe
提出日時 2022-08-05 21:24:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,984 bytes
コンパイル時間 1,477 ms
コンパイル使用メモリ 138,136 KB
実行使用メモリ 10,568 KB
最終ジャッジ日時 2023-10-14 00:02:53
合計ジャッジ時間 5,004 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 21 ms
5,336 KB
testcase_06 AC 44 ms
9,368 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 13 ms
4,748 KB
testcase_11 WA -
testcase_12 AC 28 ms
6,836 KB
testcase_13 WA -
testcase_14 AC 64 ms
10,568 KB
testcase_15 WA -
testcase_16 AC 62 ms
10,232 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 63 ms
10,244 KB
testcase_20 AC 64 ms
10,304 KB
testcase_21 AC 63 ms
10,420 KB
testcase_22 AC 62 ms
10,316 KB
testcase_23 WA -
testcase_24 AC 50 ms
10,412 KB
testcase_25 AC 51 ms
10,432 KB
testcase_26 AC 50 ms
10,480 KB
testcase_27 WA -
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 WA -
testcase_33 AC 1 ms
4,352 KB
testcase_34 WA -
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,352 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 61 ms
10,396 KB
testcase_40 AC 55 ms
10,156 KB
testcase_41 AC 59 ms
10,276 KB
testcase_42 AC 59 ms
10,216 KB
testcase_43 AC 60 ms
10,340 KB
testcase_44 AC 64 ms
10,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

class Add_Segment_Tree {
	vector<long long int>v;
	long long int ret;
	int num;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		v[place] = Update(place * 2) + Update(place * 2 + 1);
		return v[place];
	}
public:
	Add_Segment_Tree(int n) {
		n++;
		num = 1;
		while (num < n * 2)num *= 2;
		v.resize(num, 0);
	}
	void Add(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] += num;
		if (!update)return;
		place /= 2;
		while (place) {
			v[place] = v[place * 2] + v[place * 2 + 1];
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int Sum(int a, int b) {
		ret = 0;
		b++;
		for (a += num / 2, b += num / 2; a < b; a >>= 1, b >>= 1) {
			if (a & 1)ret += v[a++];
			if (b & 1)ret += v[--b];
		}
		return ret;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	vector<int>v(N);
	for (auto& i : v)cin >> i;
	auto w = v;
	sort(w.begin(), w.end());
	cout << w[N / 2 - 1] << " ";
	vector<int>a;
	vector<int>b;
	for (int i = 0; i < N; i++) {
		if (v[i] <= N / 2)b.push_back(i);
		else a.push_back(i);
	}
	vector < int>x;
	for (int i = 0; i < N / 2; i++) {
		x.push_back(a[i]);
		x.push_back(b[i]);
	}
	if (x.size() < v.size())x.push_back(a.back());
	long long ans = 0;
	Add_Segment_Tree asg(N);
	for (auto i : x) {
		ans += asg.Sum(i, N - 1);
		asg.Add(i, 1, true);
	}
	cout << ans << endl;
}
0