結果

問題 No.696 square1001 and Permutation 5
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-06-02 20:45:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4,865 ms / 10,000 ms
コード長 2,174 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 108,264 KB
実行使用メモリ 5,332 KB
最終ジャッジ日時 2023-10-17 23:07:28
合計ジャッジ時間 19,241 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4,865 ms
5,332 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 12 ms
4,348 KB
testcase_07 AC 42 ms
4,348 KB
testcase_08 AC 171 ms
4,408 KB
testcase_09 AC 1,146 ms
4,760 KB
testcase_10 AC 4,840 ms
5,332 KB
testcase_11 AC 16 ms
5,268 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0