Mentors程序员的导师

CodeForces - 978F

In BerSoft n programmers work, the programmer i is characterized by a
skill ri.

A programmer a can be a mentor of a programmer b if and only if the
skill of the programmer a is strictly greater than the skill of the
programmer b (ra>rb) and programmers a and b are not in a quarrel.

You are given the skills of each programmers and a list of k pairs of
the programmers, which are in a quarrel (pairs are unordered). For
each programmer i, find the number of programmers, for which the
programmer i can be a mentor.

Input

The first line contains two integers n and k (2≤n≤2⋅105, 0≤k≤min(2⋅105,n⋅(n−1)2)) — total number of programmers and number of pairs of programmers which are in a quarrel.The second line contains a sequence of integers r1,r2,…,rn (1≤ri≤109), where ri equals to the skill of the i-th programmer. Each of the following k lines contains two distinct integers x, y (1≤x,y≤n, x≠y) — pair of programmers in a quarrel. The pairs are
unordered, it means that if x is in a quarrel with y then y is in aquarrel with x. Guaranteed, that for each pair (x,y) there are noother pairs (x,y) and (y,x) in the input.

Output

Print n integers, the i-th number should be equal to the number of programmers, for which the i-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.

在这里插入图片描述
题意找比自己小的数的个数,但是不能存在争议

#include<bits/stdc++.h>
using namespace std;
int a[200005],b[200005],x[200005];
int main()
{
	int n,k;
	map<int,vector<int>>m;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		b[i]=a[i];
	}
	for(int i=1;i<=k;i++)
	{
		int  x,y;
		cin>>x>>y;
		m[x].push_back(y);
		m[y].push_back(x);
	}
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
	{
		int t=lower_bound(b+1,b+n+1,a[i])-b-1;
		x[i]=t;
	}
	for(int i=1;i<=n;i++)
	{
		if(m[i].size()>=1)
		{
			for(int j=0;j<m[i].size();j++)
			{
				if(a[i]>a[m[i][j]])x[i]--;
			}
			
		}
	}
	for(int i=1;i<=n;i++)cout<<x[i]<<" ";
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值