RE 求条
查看原帖
RE 求条
1433474
Meng_Xiangyu楼主2025/1/22 10:47

样例也不过

// Problem: M - 三元上升子序列
// Contest: Virtual Judge - 第2章:进阶数据结构2(线段树、树状数组)
// URL: https://vjudge.net/contest/629231#problem/M
// Memory Limit: 128 MB
// Time Limit: 1000 ms

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fir first
#define sec second
#define fst ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n' 
const int N=1e6+5,INF=0x3f3f3f3f3f3f3f3f;
int ans=0;

int n,res=0;
int a[N];
int t[N];
int b[N];
int lb(int x){return x&-x;}
void plu(int x){for(;x<=n;x+=lb(x))b[x]++;}
int get(int x){int y=0;for(;x;x-=lb(x))y+=b[x];return y;}

signed main(){
	fst
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	for(int i=1;i<=n;i++){
		int x=get(a[i]-1);
		ans+=x*(x-1)/2/res;//出了问题
		int y=get(a[i])-x;
		res+=y;
		plu(a[i]);
	}
	cout << ans << endl;
	return 0;
}
2025/1/22 10:47
加载中...