結果

問題 No.694 square1001 and Permutation 3
ユーザー beetbeet
提出日時 2018-06-08 22:42:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 812 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 173,284 KB
実行使用メモリ 221,420 KB
最終ジャッジ日時 2023-09-13 00:00:34
合計ジャッジ時間 9,139 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

template<typename T> 
struct BIT{
  Int n;
  unordered_map<Int, T> bit;
  BIT(Int n):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;
  }
};

struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//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)1.01e9);
  
  using ll = long long;
  ll 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