結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー hedwig100hedwig100
提出日時 2020-05-09 11:31:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,500 ms
コード長 904 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 166,508 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 18:40:19
合計ジャッジ時間 2,268 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PL;
typedef pair<int,int> P;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

template<class T> class BinaryIndexedTree {
    int N;
    vector<T> bit;
    
    public :
    BinaryIndexedTree(int _N): N(_N){
        bit = vector<T>(N + 1,0);
    }

    void add(int i,int x) {
        while (i <= N) {
            bit[i] += x;
            i += (i & -i);
        }
    }

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

int main() {
    int N; cin >> N;
    vector<int> M(N);
    rep(i,N) cin >> M[i];
    
    int ans = 0;
    BinaryIndexedTree<int> bit(N);
    rep(i,N) {
        ans += i - bit.sum(M[i]);
        bit.add(M[i],1);
    }
    cout << ans << endl;
}
0