結果

問題 No.694 square1001 and Permutation 3
ユーザー kotatsugamekotatsugame
提出日時 2020-02-21 01:56:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,150 ms / 3,000 ms
コード長 902 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 75,432 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-17 06:39:58
合計ジャッジ時間 9,218 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0):n(n_),bit(n_+1){}
	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 lower_bound(T k)//k<=sum(ret)
	{
		if(k<=0)return 0;
		int ret=0,i=1;
		while((i<<1)<=n)i<<=1;
		for(;i;i>>=1)
			if(ret+i<=n&&bit[ret+i]<k)k-=bit[ret+=i];
		return ret+1;
	}
};
int N,A[5<<17],B[5<<17],C[5<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		C[i]=A[i];
	}
	sort(C,C+N);
	long cnt=0;
	BIT<int>P(N);
	for(int i=0;i<N;i++)
	{
		B[i]=lower_bound(C,C+N,A[i])-C;
		cnt+=i-P.sum(B[i]+1);
		P.add(B[i]+1,1);
	}
	cout<<cnt<<endl;
	for(int i=0;i<N-1;i++)
	{
		cnt-=B[i];
		cnt+=C+N-upper_bound(C,C+N,A[i]);
		cout<<cnt<<endl;
	}
}
0