結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー glretoglreto
提出日時 2021-05-12 17:45:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,500 ms
コード長 1,287 bytes
コンパイル時間 984 ms
コンパイル使用メモリ 111,264 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 09:29:17
合計ジャッジ時間 2,048 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 12 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 <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
#include<map>
#include<random>
#include<complex>
#include<math.h>
#include<functional>
#include<stack>
#include<queue>
#include<unordered_map>
#include<set>
#include<numeric>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf = 0x3fffffff;
const ll INF = 1e18;
class BIT {
public:
	int n; vector<ll> a;
	BIT(int n) :n(n), a(n + 1, 0) {}
	void add(int i, ll x) {
		i++;
		if (i == 0)return;
		for (int j = i; j <= n; j += (j & -j)) a[j] += x;
	}ll sum(int i) {
		i++; ll sum = 0;
		if (i == 0)return sum;
		for (int j = i; j > 0; j -= (j & -j)) sum += a[j];
		return sum;
	}
};
int main() {
    int n; cin >> n; ll sum = 0,m;
    BIT bit(n + 1);
    rep(i, n) {
        cin >> m; sum += i - bit.sum(m);
		bit.add(m, 1);
    }cout << sum << endl;
}
0