Advertisement
Guest User

020-Toilet

a guest
Feb 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. vector<int> V;
  4. vector<bool> Q;
  5. bool room[20];
  6. int num[100020];
  7. int ind[100020];
  8. bool check;
  9. bool q[100020];
  10. int in;
  11. int cur;
  12. int main()
  13. {
  14.     int n,m;
  15.     scanf("%d%d",&n,&m);
  16.     int a,b;
  17.     int n2=n*2;
  18.     while(n2--){
  19.         scanf("%d%d",&a,&b);
  20.         if(a==1){
  21.             check=false;
  22.             for(int i=1;i<=m;i++){
  23.                 if(!room[i]){
  24.                     room[i]=true;
  25.                     num[b]=i;
  26.                     check=true;
  27.                     i=m+1;
  28.                 }
  29.             }
  30.             if(!check){
  31.                 V.push_back(b);
  32.             }
  33.         }
  34.         else if(a==2){
  35.             if(num[b]!=0){
  36.                 room[num[b]]=false;
  37.                 if(!V.empty()){
  38.                     while(!V.empty() && q[V.front()]) V.erase(V.begin());
  39.                     if(!V.empty()){
  40.                         room[num[b]]=true;
  41.                         num[V.front()]=num[b];
  42.                         V.erase(V.begin());
  43.                     }
  44.                 }
  45.             }
  46.             else{
  47.                 q[b]=true;
  48.             }
  49.  
  50.         }
  51.     }
  52.     for(int i=1;i<=n;i++) printf("%d\n",num[i]);
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement