Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <memory.h>
  5. #include <stdlib.h>
  6. #include <iostream>
  7. #include <time.h>
  8. #include <algorithm>
  9. #include <math.h>
  10. #include <vector>
  11. #include <set>
  12. #include <queue>
  13. #include <stack>
  14. #include <bitset>
  15. #include <string>
  16. #include <cstring>
  17. #include <cassert>
  18. #include <fstream>
  19. #include <map>
  20. #include <unordered_map>
  21. #include <deque>
  22. #include <unordered_set>
  23.  
  24. using namespace std;
  25.  
  26.  
  27. int n;
  28. map <string, int> used;
  29. vector <pair <string, int>> arr;
  30. int main() {
  31.  
  32. srand(time(0));
  33. cin >> n;
  34. for (int i = 0; i < n; i++) {
  35. string type;
  36. cin >> type;
  37. if (type == "add") {
  38. int x;
  39. string name;
  40. cin >> x >> name;
  41. used[name] += x;
  42. if (arr.size() && arr.back().first == name) {
  43. arr.back().second += x;
  44. }
  45. else {
  46. arr.push_back({ name, x });
  47. }
  48. }
  49. else if (type == "delete") {
  50. int x;
  51. cin >> x;
  52. for (; x > 0;) {
  53. if (arr.back().second <= x) {
  54. x -= arr.back().second;
  55. used[arr.back().first] -= arr.back().second;
  56. arr.pop_back();
  57. }
  58. else {
  59. used[arr.back().first] -= x;
  60. arr.back().second -= x;
  61. x = 0;
  62. }
  63. }
  64. }
  65. else {
  66. string name;
  67. cin >> name;
  68. if (!used.count(name)) {
  69. cout << "0\n";
  70. }
  71. else {
  72. cout << used[name] << "\n";
  73. }
  74. }
  75. }
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement