結果

問題 No.696 square1001 and Permutation 5
ユーザー ats5515ats5515
提出日時 2018-06-08 23:44:24
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,071 bytes
コンパイル時間 1,844 ms
コンパイル使用メモリ 77,628 KB
実行使用メモリ 4,648 KB
最終ジャッジ日時 2023-09-13 00:27:06
合計ジャッジ時間 1,889 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;


#define int long long
int MOD = 1000000007;
template <class T>
struct fenwick_tree {
	vector<T> x;
	fenwick_tree(int n) : x(n, 0) { }
	T sum(int i, int j) {
		if (i == 0) {
			T S = 0;
			for (j; j >= 0; j = (j & (j + 1)) - 1) S += x[j];
			return S;
		}
		else return sum(0, j) - sum(0, i - 1);
	}
	void add(int k, T a) {
		for (; k < x.size(); k |= k + 1) x[k] += a;
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		//A[i] = N - i;
		A[i]--;
	}
	fenwick_tree<int> ft(N);
	for (int i = 0; i < N; i++) {
		ft.add(i, 1);
	}
	for (int i = 0; i < N - 1; i++) {
		int k = ft.sum(0, A[i] - 1);
		ft.add(A[i], -1);
		//cerr << k << endl;
		res += k;
		res *= N - i - 1;
	}
	//cout << ((res + 1) - res) << endl;
	//bigint x = 1;
	res++;
	cout << res << endl;
}
0