結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー potoooooooopotoooooooo
提出日時 2018-12-15 01:18:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,500 ms
コード長 598 bytes
コンパイル時間 1,571 ms
コンパイル使用メモリ 170,804 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 10:38:46
合計ジャッジ時間 2,396 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

// one-based numbering
template<class T> struct Fenwick {
    vector<T> bit; int N;
    Fenwick(int n) {
      N = n;
      bit.resize(n+1, 0);
    }
    void add(int a, T w) {
      for (int x = a; x <= N; x += x & -x) bit[x] += w;
    }
    T sum(int a) {
      T ret = 0;
      for (int x = a; x > 0; x -= x & -x) ret += bit[x];
      return ret;
    }
};

int main() {
	int n; cin >> n;
	Fenwick<long long> f(n);
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		ans += i - f.sum(k);
		f.add(k, 1);
	}
	cout << ans << endl;
}
0