結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー kotatsugamekotatsugame
提出日時 2018-10-06 18:47:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 474 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 69,444 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 18:05:34
合計ジャッジ時間 1,327 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
6,940 KB
testcase_15 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0,T a=0):n(n_),bit(n_+1,a){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
};
int n,a[30000],x;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	BIT<int>b(n);
	for(int i=0;i<n;i++)
	{
		x+=b.sum(a[i]);
		b.add(a[i],1);
	}
	cout<<x<<endl;
}
0