結果

問題 No.694 square1001 and Permutation 3
ユーザー beetbeet
提出日時 2018-06-08 22:34:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 724 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 174,160 KB
実行使用メモリ 13,520 KB
最終ジャッジ日時 2023-09-12 23:59:29
合計ジャッジ時間 11,692 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T> 
struct BIT{
  Int n;
  map<Int, T> bit;
  //1-indexed
  BIT():n(-1){}
  BIT(Int n_,T d):n(n_){}
  
  T sum(Int i){
    T s=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> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  BIT<Int> bit((Int)1e10,0);
  Int ans=0;
  for(Int i=0;i<n;i++){
    ans+=i-bit.sum(a[i]);
    bit.add(a[i],1);
  }
  for(Int i=0;i<n;i++){
    cout<<ans<<endl;
    ans-=bit.sum(a[i]-1);
    ans+=n-bit.sum(a[i]);
  }
  return 0;
}
0