Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <algorithm>
  6. #include <stack>
  7. #include <queue>
  8. #include <deque>
  9. #include <set>
  10. #include <map>
  11. #include <cmath>
  12. #include <unordered_map>
  13. #include <unordered_set>
  14. #include <numeric>
  15. #include <fstream>
  16. #include <functional>
  17. #include <iomanip>
  18. #include <cctype>
  19. #include <iterator>
  20. #include <utility>
  21. #include <bitset>
  22. #include <tuple>
  23.  
  24. #define frt(s, n, t) for(int i = s; (i > n && t < 0) || (i < n && t > 0); i += t)
  25. #define fr(s, n) for (int i = s; i < n; i++)
  26. #define frj(s, n) for (int j = 0; j < n; j++)
  27. #define eol "\n"
  28. #define pb push_back
  29. #define ft first
  30. #define sd second
  31.  
  32. using namespace std;
  33.  
  34. typedef long long unsigned ull;
  35. typedef long long ll;
  36.  
  37. typedef unordered_map<int, int> umii;
  38. typedef unordered_set<int> usi;
  39. typedef unordered_set<ll> usll;
  40. typedef unordered_set<ull> usull;
  41. typedef vector<int> vint;
  42. typedef pair<int, int> pairI;
  43. typedef pair<string, int> psi;
  44. typedef vector<pair<int, int>> vpi;
  45.  
  46. int main() {
  47.     //ifstream in("input.txt");
  48.     //ofstream out("output.txt");
  49.     ios::sync_with_stdio(0);
  50.     cin.tie(NULL);
  51.     pair<vector<pairI>, vector<pairI>> arr[200001];
  52.     int n, m, k, x, y;
  53.     cin >> n >> k;
  54.     vector<pairI> v(n);
  55.     int maxG = 0;
  56.     fr(0, n) {
  57.         cin >> v[i].ft >> v[i].sd;
  58.         maxG = max(maxG, v[i].sd);
  59.         arr[v[i].ft].ft.pb({ v[i].sd,  i });
  60.         arr[v[i].sd].sd.pb({ v[i].sd,  i });
  61.     }
  62.     set<pairI> s;
  63.     vint r;
  64.     fr(0, maxG+1) {
  65.         for (auto x : arr[i].ft) {
  66.             if (v[x.sd].first > 0)
  67.                 s.insert(x);
  68.         }
  69.         while (s.size() > k) {
  70.             pairI last = *(--s.end());
  71.             s.erase(--s.end());
  72.             v[last.sd].first = -1;
  73.             r.push_back(last.sd);
  74.         }
  75.         for (auto x : arr[i].sd) {
  76.             if (v[x.sd].first > 0)
  77.                 s.erase(x);
  78.         }
  79.     }
  80.     cout << r.size() << eol;
  81.     for (int x : r) {
  82.         cout << x+1 << " ";
  83.     }
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement