結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー 👑 CleyL
提出日時 2020-03-07 17:37:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 2,500 ms
コード長 592 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 68,352 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 01:42:53
合計ジャッジ時間 1,469 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

template<typename T>
struct BIT{//1_Indexed
  int n;
  vector<T> bit;
  BIT(int n_):n(n_+1),bit(n,0){}

  T sum(int a){
  int ret = 0;
  for(int i = a; i > 0; i -= i & -i) ret += bit[i];
  return ret;
  }

  void add(int a,int w){
    for(int i = a; i <= n; i += i & -i)bit[i] += w;
  }

  T query(int l,int r){
    return sum(l-1)-sum(r-1);
  }

};

int main(){
  int n;cin>>n;
  BIT<int> a(n);
  int ans = 0;
  for(int i = 0; n > i; i++){
    int t;cin>>t;
    a.add(t,1);
    ans += (i+1)-a.sum(t);
  }
  cout << ans << endl;

}
0