結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー chocoruskchocorusk
提出日時 2018-10-05 22:22:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 2,500 ms
コード長 649 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 84,088 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-02 17:51:25
合計ジャッジ時間 1,418 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
   
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int bit[30001], n;
 
int sum(int i){
	int s=0;
	while(i>0){
		s+=bit[i];
		i-=(i&(-i));
	}
	return s;
}
 
void add(int i){
	while(i<=n){
		bit[i]+=1;
		i+=(i&(-i));
	}
}

int main()
{
	cin>>n;
	int ans=0;
	for(int i=0; i<n; i++){
		int m;
		cin>>m;
		ans+=(i-sum(m));
		add(m);
	}
	cout<<ans<<endl;
    return 0;
}
0