結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー HaarHaar
提出日時 2018-10-06 08:17:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 2,500 ms
コード長 601 bytes
コンパイル時間 1,613 ms
コンパイル使用メモリ 162,068 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 18:03:02
合計ジャッジ時間 1,953 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 9 ms
6,944 KB
testcase_12 AC 9 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class BIT{
private:
  vector<int> tree;
  int n;
public:
  BIT(int size){tree.resize(size+1); for(auto v : tree){v = 0;}; n = size;}
  void update(int x, int a){while(x <= n){tree[x] += a; x += (x & (-x));}}
  int get(int x){int a = 0; while(x > 0){a += tree[x]; x -= (x & (-x));} return a;}
};

int main(){
  int n;
  cin >> n;
  vector<int> ms(n);
  for(int i=0; i<n; ++i) cin >> ms[i];

  BIT bit(30000);
  int count = 0;
  for(int i=n-1; i>=0; --i){
    count += bit.get(ms[i]);
    bit.update(ms[i],1);
  }

  cout << count << endl;
  
  return 0;
}
0