1
0

CodeForces-1139E.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <functional>
  2. #include <iostream>
  3. #include <vector>
  4. using namespace std;
  5. int main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(nullptr);
  8. int n, clubs; cin >> n >> clubs;
  9. vector<int> potential(n), club(n);
  10. for (int &x : potential) cin >> x;
  11. for (int &x : club) cin >> x, --x;
  12. int days; cin >> days;
  13. vector<int> removed(days); vector<bool> will_remove(n, false);
  14. for (int &x : removed) { cin >> x; --x; will_remove[x] = true; }
  15. constexpr int max_potential = 5000;
  16. vector<vector<int>> graph(max_potential + 1);
  17. for (int i = 0; i < n; ++i) if (!will_remove[i]) graph[potential[i]].push_back(club[i]);
  18. vector<int> match_club(clubs, -1), seen(clubs, 0);
  19. int token = 0;
  20. function<bool(int)> augment = [&](int p) {
  21. for (int c : graph[p]) if (seen[c] != token) {
  22. seen[c] = token;
  23. if (match_club[c] == -1 || augment(match_club[c])) {
  24. match_club[c] = p; return true;
  25. }
  26. }
  27. return false;
  28. };
  29. int mex = 0;
  30. auto advance = [&] {
  31. while (mex <= clubs) {
  32. ++token;
  33. if (!augment(mex)) break;
  34. ++mex;
  35. }
  36. };
  37. advance();
  38. vector<int> answer(days);
  39. for (int day = days - 1; day >= 0; --day) {
  40. answer[day] = mex;
  41. int student = removed[day];
  42. graph[potential[student]].push_back(club[student]);
  43. advance();
  44. }
  45. for (int x : answer) cout << x << '\n';
  46. }