为什么寄了!!!!

071maozihan 2022-11-22 13:03:40 11 返回题目

洛谷上一道类似的题目就过了! 但是青藤寄了!(洛谷上连快读都没加)

CODE

#include<bits/stdc++.h>
//#define int long long
using namespace std;
const long long maxn=1e5+10;
int c[maxn];
int l[maxn],r[maxn];
int a[maxn]; 
int n,ans;
int inline read(){
	int s = 0,w = 1;
	char ch;
	ch = getchar();
	while(ch > '9' || ch < '0'){
		if(ch == '-') w = -1;
		ch = getchar();
	}
	while(ch <= '9' && ch >= '0'){
		s=s*10+ch-'0';
		ch = getchar();
	}
	return s*w;
}
int lowbit(int x){
	return x&-x;
}
void up_add(int x,int u){
	if(x >= maxn) return ;
	c[x]+=u;
	up_add(x+lowbit(x),u);
}
int sum(int x){
	if(x <= 0)return 0;
	return sum(x-lowbit(x))+c[x];
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++){
		a[i] = read();
	}
	for(int i=1;i<=n;i++){
		up_add(a[i],1);
		l[i] = sum(a[i]-1);
	}
	for(int i=1;i<maxn;i++){
		c[i] = 0;
	}
	for(int i=n;i>=1;i--){
		up_add(a[i],1);
		r[i] = sum(a[i]-1);
		ans+=l[i]*r[i];
	}
	printf("%lld",ans);
	return 0;
}

PS:洛谷题目传送门:https://www.luogu.com.cn/problem/P1637

{{ vote && vote.total.up }}