WA 0pts
查看原帖
WA 0pts
765958
lottle1212楼主2023/3/28 21:01

蒟蒻代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mxn = 5e5;
const ll N = mxn + 10;
ll n, i, sum, a[N], c[N];
struct node { ll x, id; } num[N];
bool cmp(node x, node y) { return x.x <= y.x; }
ll query(ll x) {
	ll sum = 0;
	while (x) sum += c[x], x -= (x & -x);
	return sum;
}
void update(ll x, ll y) {
	while (x <= n) c[x] += y, x += (x & -x);
}
signed main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(ll i = 1; i <= n; ++ i) cin >> a[i], num[i] = {a[i], i};
	sort(num + 1, num + 1 + n, cmp);
	for(ll i = 1; i <= n; ++ i) a[num[i].id] = i;
	for(ll i = n; i >= 1; -- i)	sum += query(a[i] - 1), update(a[i], 1);
	cout << sum;
	return 0;
}

第一个数据点,答案 258911,输出 258912,精准避开正确答案 QAQ。

2023/3/28 21:01
加载中...