Home >Web Front-end >HTML Tutorial >Codeforces Round #261 (Div. 2) D Tree Array Application_html/css_WEB-ITnose

Codeforces Round #261 (Div. 2) D Tree Array Application_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:59:47913browse

Looking at the meaning of the question: the number of [1,i] equal to a[i] is greater than the number of [,jn] equal to a[j] and i


int n;int aa[1000000 + 55];int bb[1000000 + 55];int c[1000000 + 55];map	mp;ll lowbit(ll x) {	return x&(-x);}void add(int i,int val) {	while(i <= n) {		c[i] += val;		i += lowbit(i);	}}ll get_sum(int i) {	ll sum = 0;	while(i) {		sum += c[i];		i -= lowbit(i);	}	return sum;}void init() {	memset(c,0,sizeof(c));	memset(aa,0,sizeof(aa));	memset(bb,0,sizeof(bb));	mp.clear();}int main() {	while(scanf("%d",&n) == 1) {		init();		for(int i=1;i<=n;i++)scanf("%d",&aa[i]);		for(int i=1;i<=n;i++) {			mp[aa[i]]++;			bb[i] = mp[aa[i]];			add(bb[i],1);		}		mp.clear();		ll ans = 0ll;		for(int i=n;i>=1;i--) {			add(bb[i],-1);			mp[aa[i]]++;			int tmp = mp[aa[i]];			ans += i - get_sum(tmp) - 1;		}		cout< 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn