結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー nikkukunnikkukun
提出日時 2021-03-12 22:26:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,298 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 176,884 KB
実行使用メモリ 33,280 KB
最終ジャッジ日時 2024-04-22 13:29:26
合計ジャッジ時間 7,706 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 123 ms
26,880 KB
testcase_23 AC 32 ms
9,472 KB
testcase_24 AC 28 ms
8,448 KB
testcase_25 AC 130 ms
28,160 KB
testcase_26 AC 155 ms
32,640 KB
testcase_27 AC 135 ms
29,184 KB
testcase_28 AC 168 ms
33,024 KB
testcase_29 AC 47 ms
12,288 KB
testcase_30 AC 35 ms
9,728 KB
testcase_31 AC 163 ms
32,640 KB
testcase_32 AC 44 ms
11,904 KB
testcase_33 AC 6 ms
5,376 KB
testcase_34 AC 52 ms
13,312 KB
testcase_35 AC 152 ms
30,592 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

map<int, set<int>> intToSet;

int a[N];

struct BITree {
	int t[N];
	int lowbit(int x) {
		return x & -x;
	}
	void add(int x, int det) {
		for (; x < N; x += lowbit(x))
			t[x] += det;
	}
	int query(int x) {
		int ret = 0;
		for (; x; x -= lowbit(x))
			ret += t[x];
		return ret;
	}
};
BITree bt;

int main() {
	ios::sync_with_stdio(0);

	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		intToSet[a[i]].insert(i);
		bt.add(i, 1);
	}
	sort(a + 1, a + n + 1);

	int pre = n + 1;
	int ans = 0;
	for (int i = n; i >= 1; i--) {
		auto &s = intToSet[a[i]];
		auto p = s.lower_bound(pre);
		int now;
		int det = 0;
		if (p != s.begin()) {
			p--;
			now = *p;
			det = bt.query(pre) - bt.query(now);
		} else {
			now = *s.rbegin();
			det = bt.query(pre) - (bt.query(n) - bt.query(now));
		}
		s.erase(now);
		bt.add(now, -1);
		ans += det != 0;
		pre = now;
	}
	cout << ans << endl;

	return 0;
}
0