Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <list>
- using namespace std;
- vector<bool> toilet;
- vector<int> history;
- list<int> line;
- list<int>::iterator itr;
- int np, nt, x;
- char cmd;
- bool found;
- void PrintVector(vector<int> &history, int sz){
- for(int i = 1; i <= sz; ++i){
- cout << history[i] << " ";
- }
- cout << "\n";
- }
- void PrintList(list<int> &line){
- for(auto x : line){
- cout << x << " ";
- }
- cout << "\n";
- }
- int main(){
- scanf("%d", &np);
- scanf("%d", &nt);
- history.assign(np + 1, -1);
- toilet.assign(nt + 1, false);
- for(int i = 1; i <= 2 * np; ++i){
- scanf(" %c %d", &cmd, &x);
- if(cmd == '1'){
- found = false;
- for(int j = 1; j <= nt; ++j){
- if(toilet[j] == false){
- toilet[j] = true;
- history[x] = j;
- found = true;
- break;
- }
- }
- if(!found){
- line.push_back(x);
- }
- } else if(cmd == '2'){
- if(history[x] == -1){ /// In Line
- history[x] = 0;
- } else {
- while(!line.empty()){
- if(history[line.front()] == 0){
- line.erase(line.begin());
- } else {
- break;
- }
- }
- if(!line.empty()){
- history[line.front()] = history[x];
- line.erase(line.begin());
- } else {
- toilet[history[x]] = false;
- }
- }
- }
- }
- for(int i = 1; i <= np; ++i){
- cout << history[i] << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement