結果

問題 No.696 square1001 and Permutation 5
ユーザー square1001square1001
提出日時 2018-06-09 11:23:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 707 bytes
コンパイル時間 8,886 ms
コンパイル使用メモリ 339,116 KB
実行使用メモリ 22,768 KB
最終ジャッジ日時 2023-09-13 01:46:24
合計ジャッジ時間 31,119 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
int main() {
	using boost::multiprecision::cpp_int;
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> p(n), bit(n);
	vector<cpp_int> a(n), b(n);
	for (int i = 0; i < n; i++) cin >> p[i];
	for (int i = n - 1; i >= 0; i--) {
		int x = 0;
		for (int j = p[i] - 1; j >= 1; j -= j & (-j)) x += bit[j];
		for (int j = p[i]; j < n; j += j & (-j)) bit[j]++;
		a[n - i - 1] = x;
		b[i] = i + 1;
	}
	for (int i = 1; i < n; i <<= 1) {
		for (int j = 0; j + i < n; j += 2 * i) {
			a[j] = a[j] + b[j] * a[j + i];
			b[j] = b[j] * b[j + i];
		}
	}
	cout << a[0] + 1 << endl;
	return 0;
}
0