Algo lab/zamoo

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
#include <iostream>
#include <list>

using namespace std;

const int MAX_BALL_NUMBER = 200010;

int n;
list<int> balls;
bool in_list[MAX_BALL_NUMBER];

void init()
{
  for(int i = 1; i < MAX_BALL_NUMBER; i++)
    in_list[i] = false;
}

bool check(int a)
{
  return in_list[a];
}

void delete_from_front(int a)
{
}

void delete_from_back(int a)
{
}

int main()
{
  init();
  
  cin >> n;
  for(int i=0; i<n; i++) {
    int d, a;
    cin >> d >> a;
    if(d == 0) {
      // check if ball a is in the list?
      if(check(a)) {
        delete_from_front(a);
      } else {
        balls.push_front(a);
        in_list[a] = true;
      }
    } else {
      if(check(a)) {
        delete_from_back(a);
      } else {
        balls.push_back(a);
        in_list[a] = true;
      }
    }
  }
}