a53

supermarket_of

a53
Feb 19th, 2019
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <fstream>
  2. #define VMAX 1000002
  3. #define NMAX 1000002
  4. #define ZMILION 10000000
  5. using namespace std;
  6. ifstream fin("supermarket.in");
  7. ofstream fout("supermarket.out");
  8.  
  9. int c[2][NMAX];
  10. int unde[VMAX];
  11. int inc[2]={1,1}, sf[2], lg[2];
  12. int n;
  13.  
  14. int main()
  15. {int i, tip, x, casa;
  16. fin >> n;
  17. for (i = 1; i <= n; i++)
  18. {
  19. fin >> tip;
  20. if(tip <= 2)
  21. {tip--;
  22. while (inc[tip]<=sf[tip] && unde[c[tip][inc[tip]]]%ZMILION!=inc[tip])
  23. {inc[tip]++;}
  24. if (inc[tip]>sf[tip])
  25. fout << "-1\n";
  26. else
  27. {
  28. fout<<c[tip][inc[tip]]<<'\n';
  29. inc[tip]++; lg[tip]--;
  30. }
  31. }
  32. else
  33. {
  34. fin>>x;
  35. if (tip == 3)
  36. {
  37. casa=0;
  38. if (lg[1]<lg[0]) casa=1;
  39. fout<<casa+1<<'\n';
  40. sf[casa]++; c[casa][sf[casa]]=x;
  41. unde[x]=sf[casa]+casa*ZMILION;
  42. lg[casa]++;
  43. }
  44. else //4
  45. {
  46. casa=unde[x]/ZMILION;
  47. lg[casa]--;
  48. unde[x]=0;
  49. }
  50.  
  51. }
  52. }
  53. fout.close();
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment