978F - Mentors - CodeForces Solution


binary search data structures implementation *1500

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
 
int n,k;
int u,v;
int r[N];
int ans[N];
vector<PII> A;
vector<int> V[N];
 
bool cmp(PII a,PII b){
    if(a.se!=b.se) return a.se<b.se;
    if(a.se==b.se) return a.fi<b.fi;
}
 
int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>k;
     for(int i=0;i<n;++i){
         cin>>r[i];
         A.pb({i,r[i]});
     }
 
     for(int i=1;i<=k;++i){
         cin>>u>>v;
         if(A[u-1].se>A[v-1].se) V[u-1].pb(v-1);
         else if(A[v-1].se>A[u-1].se) V[v-1].pb(u-1);
     }
     sort(A.begin(),A.end(),cmp);
     sort(r,r+n);
     for(int i=1;i<n;++i){
         int pos=lower_bound(r,r+n,r[i])-r;
         int cnt=V[A[i].fi].size();
         ans[A[i].fi]=max(0,pos-cnt);
     }
     for(int i=0;i<n;++i) printf("%d ",ans[i]);
 
    return 0;
}


Comments

Submit
0 Comments
More Questions

1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves
230B - T-primes
630A - Again Twenty Five
1234D - Distinct Characters Queries
1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers
1624A - Plus One on the Subset
350A - TL
1487A - Arena
1520D - Same Differences
376A - Lever
1305A - Kuroni and the Gifts
1609A - Divide and Multiply
149B - Martian Clock
205A - Little Elephant and Rozdil