結果
| 問題 | No.742 にゃんにゃんにゃん 猫の挨拶 | 
| コンテスト | |
| ユーザー |  risujiroh | 
| 提出日時 | 2018-10-05 21:35:50 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 6 ms / 2,500 ms | 
| コード長 | 1,224 bytes | 
| コンパイル時間 | 1,511 ms | 
| コンパイル使用メモリ | 168,860 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-12 13:54:29 | 
| 合計ジャッジ時間 | 2,121 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }
template<class T> struct BIT {
  int n, h;
  V<T> t;
  BIT(int n) : n(n), h(__lg(n) + 1) { t.assign(n + 1, (T) 0); }
  void add(int x, T a) {
    for (int i = x + 1; i < n + 1; i += i & -i) t[i] += a;
  }
  int lower_bound(T s) {
    if (s <= 0) return 0;
    int res = 0;
    for (int k = 1 << h - 1; k; k >>= 1) if (res + k < n + 1 and t[res + k] < s) s -= t[res += k];
    return res + 1;
  }
  T sum(int x) {
    T res = 0;
    for (int i = x; i; i -= i & -i) res += t[i];
    return res;
  }
  T sum(int l, int r) {
    return sum(r) - sum(l);
  }
};
int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
  BIT<int> bit(n);
  int res = 0;
  for (int i = n - 1; i >= 0; i--) {
    res += bit.sum(a[i]);
    bit.add(a[i], 1);
  }
  cout << res << '\n';
}
            
            
            
        