Cod sursa(job #2661510)

Utilizator teochess2017Togan Teodor-Bogdan teochess2017 Data 22 octombrie 2020 10:08:56
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.21 kb
#include <iostream>
#include <stdio.h>
#include <vector>
#include <ctype.h>

#define MOD 1000000

using namespace std;

short lim[MOD];
vector<short>h[MOD];

FILE *fin, *fout;

int readInt(){
  int n;
  char ch;

  while(!isdigit(ch = fgetc(fin)));

  n=ch - '0';
  while(isdigit(ch = fgetc(fin))){
    n = n * 10 + ch - '0';
  }
  return n;
}

int main()
{
    int n, op, x, i, j;
    fin=fopen("hashuri.in", "r");
    n = readInt();
    fout=fopen("hashuri.out", "w");
    for(i = 0; i < n; i++){
      op = readInt();
      x = readInt();
      if(op == 1){
        h[x % MOD].push_back(x / MOD);
        lim[x % MOD]++;
      }else if(op == 2){
        j = 0;
        while((j < lim[x % MOD]) && (h[x % MOD][j] != (x / MOD))){
          j++;
        }
        if(j < lim[x % MOD]){
          h[x % MOD].erase(h[x % MOD].begin() + j);
          lim[x % MOD]--;
        }
      }else{
        j = 0;
        while((j < lim[x % MOD]) && (h[x % MOD][j] != (x / MOD))){
          j++;
        }
        if(j < lim[x % MOD]){
          fprintf(fout, "1\n");
        }else{
          fprintf(fout, "0\n");
        }
      }
    }
    fclose(fin);
    fclose(fout);
    return 0;
}