Wannafly模拟赛2 A题

题目衔接:传送门


思路:很直观的我们知道在一场比赛中任意两个人的排名都有大于小于之分,那也就是说对于两个人i,j如果存在两场比赛第i个人的排名比第j个人的排名高另外一场低答案就加1,我们直接考虑三场比赛中第i个人和第j个人的排名,一共有四种情况

1:三场比赛中第i个人的排名都比第j个人的排名高、

2:三场比赛中的两场比赛第i个人的排名比第j个人排名高,另外一场比第j个人排名低

3:三场比赛中只有一场比赛第i个人的排名比第j个人的排名高,另外两场比第j个人排名低

4:三种比赛中第i个人的排名全部比第j个人的排名低

只有2和3两种情况会对答案产生贡献,那么我们直接分析1、2场比赛、1、3场比赛和2、3场比赛中第i个人和第j个人的排名情况,最后对答案除2即可

当比较1、2两场比赛的时候我们固定第一场比赛中人的排名是从高到低的,那么此时我们只需要求出第二场比赛中的逆序数即可

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 2e5 + 10;
const int INF = 1e9 + 10;
struct Num {
	int a, b;
	bool operator < (const Num &w) const {
		return a < w.a;
	}
}num[qq];
int a[qq], b[qq], c[qq];
LL sum[qq];
LL GetSum(int x) {
	LL ans = 0;
	while(x > 0) {
		ans += sum[x];
		x -= x & (-x);
	}
	return ans;
}
void UpDate(int x, int n) {
	while(x <= n) {
		sum[x] += 1;
		x += x & (-x);
	}
}
LL Solve(int *t1, int *t2, int n) {
	for(int i = 1; i <= n; ++i) {
		num[i].a = t1[i];
		num[i].b = t2[i];
		sum[i] = 0;
	}
	sort(num + 1, num + 1 + n);
	LL ans = 0;
	for(int i = n; i >= 1; --i) {
		ans += GetSum(num[i].b);
		UpDate(num[i].b, n);
	}
	return ans;
}

int main(){
	int n;	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%d%d%d", a + i, b + i, c + i);
	}
	LL ans;
	ans = Solve(a, b, n) + Solve(a, c, n) + Solve(b, c, n);
	printf("%lld\n", ans / 2);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值