Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 100010;
- const int M = 11;
- int where[N];
- bool hasppl[M];
- queue<int> Q;
- int main()
- {
- int n, m;
- scanf("%d%d", &n, &m);
- // -1 = still in queue, 0 = not in queue/quitted the queue, num = room
- for (int i = 0; i < 2*n; ++i) {
- int t, x;
- scanf("%d%d", &t, &x);
- if (t == 1) {
- where[x] = -1;
- Q.push(x); // enqueue x
- } else if (t == 2) {
- if (where[x] == -1)
- where[x] = 0;
- hasppl[where[x]] = false;
- } else {
- assert(false); // error
- }
- while (!Q.empty()) {
- x = Q.front();
- if (where[x] == 0) { // if x has already quitted the queue, skip
- Q.pop();
- continue;
- }
- assert(where[x] == -1);
- for (int i = 1; i <= m; ++i) { // find the empty toilet with min index
- if (!hasppl[i]) {
- hasppl[i] = true;
- where[x] = i;
- Q.pop();
- break;
- }
- }
- if (where[x] == -1)
- break;
- }
- }
- for (int i = 1; i <= n; ++i)
- printf("%d\n", where[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement