結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー CleyLCleyL
提出日時 2020-03-07 17:37:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,500 ms
コード長 592 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 69,172 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 02:21:24
合計ジャッジ時間 1,395 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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