Mentors程序员的导师

我只是一个虾纸丫 提交于 2020-03-09 14:46:48

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]<<" ";
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!