fork download
  1. #include <bits/stdc++.h>
  2. #include<vector>
  3. #include <map>
  4. #include<deque>
  5. #include<queue>
  6. #include <iostream>
  7. #include<cmath>
  8. #include<algorithm>
  9. #define ll long long
  10. using namespace std;
  11. bool cmd(pair<ll, pair<ll, ll>> a, pair<ll, pair<ll, ll>> b) {
  12. return a.second.first < b.second.first;
  13. }
  14. bool ok(ll mid, ll x, vector<ll>v) {
  15. sort(v.begin(), v.end());
  16. ll count = 0,sum=0;
  17. for (ll i = 0; i < v.size(); i++) {
  18. if (sum + v[i] > x) {
  19. count++;
  20. sum = 0;
  21. }
  22. sum += v[i];
  23. }
  24. //cout << "ok\n";
  25. return (count <= mid);
  26. }
  27.  
  28. int main() {
  29. ios::sync_with_stdio(0);
  30. cin.tie(NULL), cout.tie(NULL);
  31. //freopen("mex.in", "r", stdin);
  32.  
  33. ll t = 1;//cin >> t;
  34. while (t--) {
  35. ll n, q;
  36. cin >> n >> q;
  37. vector<pair<ll, pair<ll, ll>>>v(n);
  38. map<ll, ll>mp;
  39. for (ll i = 0; i < n; i++) {
  40. cin >> v[i].first;
  41. v[i].second.first = i;
  42. }
  43. while (q--) {
  44. ll x, y;
  45. cin >> x >> y;
  46. if (v[x - 1] > v[y - 1])v[x - 1].second.second--;
  47. else if (v[x - 1] < v[y - 1])
  48. v[y - 1].second.second--;
  49. }
  50. sort(v.begin(), v.end());
  51. for (ll i = 0; i < n; i++) {
  52. v[i].second.second += i;
  53. if (mp[v[i].first])v[i].second.second -= mp[v[i].first];
  54. mp[v[i].first]++;
  55.  
  56. }
  57. sort(v.begin(), v.end(), cmd);
  58. for (ll i = 0; i < n; i++) {
  59. cout << max(v[i].second.second,0LL) << " ";
  60. }
  61. }
  62.  
  63. return 0;
  64. }
  65. /*a
  66.  
  67. */
Success #stdin #stdout 0.01s 5292KB
stdin
10 4
5 4 1 5 4 3 7 1 2 5
4 6
2 1
10 8
3 5
stdout
5 4 0 5 3 3 9 0 2 5