fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <stack>
  6. #include <string>
  7. #include <vector>
  8. #include <cmath>
  9. #include <map>
  10. #include <set>
  11. #include <string.h>
  12. #include <stdlib.h>
  13.  
  14. using namespace std;
  15. // vector push_back push front top empty pop make_pair long long insert begin end
  16. typedef long long ll;
  17. typedef vector<int> vi;
  18. typedef vector<pair <int,int> > vpi;
  19. typedef vector<long long> vll;
  20. typedef pair<int,int> pi;
  21. #define F first
  22. #define S second
  23. #define PB push_back
  24. #define MP make_pair
  25. #define B begin()
  26. #define RB rbegin()
  27. #define E end()
  28. #define RE rend()
  29. #define Z size()
  30. #define REP(i,a,b) for (int i = a; i < b; i++)
  31. #define L length()
  32. #define show(a) cerr << " *** " << a << endl;
  33. #define show1(a) cerr << " /// " << a << endl;
  34. ll gcd(ll a, ll b) {return (b==0? a:gcd(b,a%b));}
  35. ll gcd(ll a, ll b, ll & x, ll & y) {
  36. if (a == 0) {
  37. x = 0;
  38. y = 1;
  39. return b;
  40. }
  41. ll x1, y1;
  42. ll d = gcd(b % a, a, x1, y1);
  43. x = y1 - (b / a) * x1;
  44. y = x1;
  45. return d;
  46. }
  47. int main()
  48. {
  49. ios_base::sync_with_stdio(false);
  50. cin.tie(NULL);
  51. cout.tie(NULL);
  52. int t,m;
  53. cin >> t >> m;
  54. int occ=0;
  55. int idx = 1;
  56. set<pi>sp;
  57. map<int,int>mp;
  58. while (t--)
  59. {
  60. string str;
  61. cin >> str;
  62. if (str=="alloc")
  63. {
  64. int x;
  65. cin >> x;
  66. if (occ+x>m)
  67. cout << "NULL\n";
  68. else
  69. {
  70. occ+=x;
  71. mp[idx]=x;
  72. sp.insert(MP(idx,x));
  73. cout << idx <<endl;
  74. idx++;
  75. }
  76. }
  77. else if (str=="erase")
  78. {
  79. int x;
  80. cin >> x;
  81. if (mp[x] != 0)
  82. {
  83. sp.erase(MP(x,mp[x]));
  84. mp[x]=0;
  85. }
  86. else
  87. cout << "ILLEGAL_ERASE_ARGUMENT\n";
  88. }
  89. else
  90. {
  91. auto t= sp.B;
  92. int x = t->F-1;
  93. occ=0;
  94. for (auto t : sp)
  95. {
  96. int p,o;
  97. p = t.F;
  98. o=t.S;
  99. sp.erase(t);
  100. sp.insert(MP(p-x,o));
  101. occ+=o;
  102. }
  103. }
  104.  
  105. }
  106. }
Time limit exceeded #stdin #stdout 5s 4400KB
stdin
Standard input is empty
stdout
Standard output is empty