結果

問題 No.696 square1001 and Permutation 5
ユーザー beetbeet
提出日時 2018-06-08 23:30:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 724 bytes
コンパイル時間 9,428 ms
コンパイル使用メモリ 394,720 KB
実行使用メモリ 9,828 KB
最終ジャッジ日時 2023-09-13 00:23:34
合計ジャッジ時間 32,021 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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<bits/stdc++.h>
using namespace std;
using Int = signed;
#include <boost/multiprecision/cpp_int.hpp>
using ll = boost::multiprecision::cpp_int;


template<typename T> 
struct BIT{
  Int n;
  vector<T> bit;
  BIT(Int n_,T d):n(n_),bit(n_+1,d){}
  
  T sum(Int i){
    T s=bit[0];
    for(Int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }
  void add(Int i,T a){
    if(i==0) return;
    for(Int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> p(n);
  for(Int i=0;i<n;i++) cin>>p[i];
  ll ans=1,x=1;
  BIT<Int> bit(n+1,0);
  for(Int i=1;i<=n;i++){
    ans+=bit.sum(p[n-i])*x;
    bit.add(p[n-i],1);
    x*=i;
  }
  cout<<ans<<endl;
  return 0;
}
0