結果
| 問題 |
No.742 にゃんにゃんにゃん 猫の挨拶
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-10-06 08:17:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,500 ms |
| コード長 | 601 bytes |
| コンパイル時間 | 1,422 ms |
| コンパイル使用メモリ | 162,216 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-12 14:02:16 |
| 合計ジャッジ時間 | 2,196 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
class BIT{
private:
vector<int> tree;
int n;
public:
BIT(int size){tree.resize(size+1); for(auto v : tree){v = 0;}; n = size;}
void update(int x, int a){while(x <= n){tree[x] += a; x += (x & (-x));}}
int get(int x){int a = 0; while(x > 0){a += tree[x]; x -= (x & (-x));} return a;}
};
int main(){
int n;
cin >> n;
vector<int> ms(n);
for(int i=0; i<n; ++i) cin >> ms[i];
BIT bit(30000);
int count = 0;
for(int i=n-1; i>=0; --i){
count += bit.get(ms[i]);
bit.update(ms[i],1);
}
cout << count << endl;
return 0;
}