結果

問題 No.696 square1001 and Permutation 5
ユーザー 👑 hos.lyric
提出日時 2019-06-02 20:45:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4,284 ms / 10,000 ms
コード長 2,174 bytes
コンパイル時間 1,303 ms
コンパイル使用メモリ 107,948 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 20:15:28
合計ジャッジ時間 16,286 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template <class T> void chmax(T &t, const T &f) { if (t < f) t = f; }
constexpr int MAX_N = 100005;
constexpr int LOG_BASE = 13;
// 32109876543210
constexpr Int BASE = 10000000000000LL;
constexpr int MAX_LEN = 40005;
int N;
int P[MAX_N];
int bit[MAX_N];
void bitIncr(int pos) {
for (int x = pos; x < N; x |= x + 1) {
++bit[x];
}
}
int bitSum(int pos) {
int ret = 0;
for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) {
ret += bit[x];
}
return ret;
}
int X[MAX_N];
int len;
Int a[MAX_LEN];
int main() {
for (; ~scanf("%d", &N); ) {
for (int i = 0; i < N; ++i) {
scanf("%d", &P[i]);
--P[i];
}
fill(bit, bit + N, 0);
for (int i = N; i--; ) {
X[N - i] = bitSum(P[i]);
bitIncr(P[i]);
}
++X[1];
// pv(X+1,X+N+1);
fill(a, a + MAX_LEN, 0);
len = 1;
a[0] = X[N];
for (int i = N - 1; i >= 1; --i) {
Int carry = X[i];
for (int j = 0; j < len; ++j) {
a[j] *= i;
a[j] += carry;
carry = a[j] / BASE;
a[j] %= BASE;
}
if (carry != 0) {
a[len++] = carry;
}
// pv(a,a+len);
}
printf("%lld", a[len - 1]);
for (int j = len - 2; j >= 0; --j) {
printf("%0*lld", LOG_BASE, a[j]);
}
printf("\n");
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0