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]<<" ";
}
来源:CSDN
作者:是Lr呀
链接:https://blog.csdn.net/m0_46297777/article/details/104750181