結果
| 問題 |
No.696 square1001 and Permutation 5
|
| コンテスト | |
| ユーザー |
kotamanegi
|
| 提出日時 | 2018-06-08 23:26:49 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,927 bytes |
| コンパイル時間 | 3,781 ms |
| コンパイル使用メモリ | 189,880 KB |
| 実行使用メモリ | 14,376 KB |
| 最終ジャッジ日時 | 2024-11-30 12:28:39 |
| 合計ジャッジ時間 | 62,389 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 8 TLE * 4 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*2
#define REP(i,n) for(long long i = 0;i < n;++i)
long long seg_tree[seg_size * 4] = {};
long long seg_find(int now, int n_l, int n_r, int w_l, int w_r) {
if (w_l <= n_l && n_r <= w_r) return seg_tree[now];
if (n_r <= w_l || w_r <= n_l) return 0;
return seg_find(now * 2, n_l, (n_l + n_r) / 2, w_l, w_r) + seg_find(now * 2 + 1, (n_l + n_r) / 2, n_r, w_l, w_r);
}
long long seg_set(int now) {
seg_tree[now] = seg_tree[now * 2] + seg_tree[now * 2 + 1];
if (now != 1) seg_set(now / 2);
return 0;
}
int main() {
iostream::sync_with_stdio(false);
int n;
cin >> n;
vector<int> hoge;
REP(i, n) {
int c;
cin >> c;
hoge.push_back(c);
seg_tree[(seg_size + c)]++;
seg_set((seg_size + c) / 2);
}
mp::cpp_int ans = 1;
mp::cpp_int hogea = 1;
for (int i = 1; i < hoge.size(); ++i) {
mp::cpp_int nya = i;
hogea *= nya;
}
for (int i = 0; i < hoge.size(); ++i) {
mp::cpp_int geko = seg_find(1, 0, seg_size, 0, hoge[i]);
ans += geko * hogea;
seg_tree[(seg_size + hoge[i])]--;
seg_set((seg_size + hoge[i]) / 2);
if (i != hoge.size() - 1) {
mp::cpp_int me = hoge.size() - i - 1;
hogea /= me;
}
}
cout << ans << endl;
return 0;
}
kotamanegi