Advertisement
RobertDeMilo

Untitled

Apr 15th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.93 KB | None | 0 0
  1. ////////#include <iostream>
  2. ////////#include <cstdint>
  3. ////////#include <queue>
  4. ////////
  5. ////////using namespace std;
  6. ////////
  7. ////////class EventManager
  8. ////////{
  9. ////////public:
  10. ////////    void Add(uint64_t time) // amortized O(1)
  11. ////////    {
  12. ////////        Adjust(time);
  13. ////////        events.push(time); // O(1)
  14. ////////    }
  15. ////////    int Count(uint64_t time) // amortized O(1)
  16. ////////    {
  17. ////////        Adjust(time);
  18. ////////        return events.size(); // O(1)
  19. ////////    }
  20. ////////private:
  21. ////////    queue<int64_t> events;
  22. ////////
  23. ////////    void Adjust(uint64_t time) // amortized O(1)
  24. ////////    {
  25. ////////        while(!events.empty()&&events.front()<=time-300) // O(Q)
  26. ////////        {
  27. ////////            events.pop(); // O(1)
  28. ////////        }
  29. ////////    }
  30. ////////};
  31. ////////
  32. ////////int main()
  33. ////////{
  34. ////////    return 0;
  35. ////////}
  36. ////////
  37. //////
  38. //////#include <iostream>
  39. //////#include <map>
  40. //////#include <string>
  41. //////
  42. //////using namespace std;
  43. //////
  44. //////static string FindNameByYear(const map<int,string>&names, int year)
  45. //////{
  46. //////  string name;
  47. //////  for(const auto& item:names)
  48. //////  {
  49. //////      if(item.first<=year)
  50. //////      {
  51. //////          name=item.second;
  52. //////      }
  53. //////      else
  54. //////      {
  55. //////          break;
  56. //////      }
  57. //////  }
  58. //////  return name;
  59. //////}
  60. //////
  61. //////
  62. //////static string FindNameByYear2(const map<int,string>&names, int year)
  63. //////{
  64. //////  auto iter_after = names.upper_bound(year);
  65. //////  string name;
  66. //////
  67. //////  if(iter_after!=names.begin())
  68. //////  {
  69. //////      name =(--iter_after)->second;
  70. //////  }
  71. //////  return name;
  72. //////}
  73. //////
  74. //////
  75. //////
  76. //////class Person
  77. //////{
  78. //////public:
  79. //////  void ChangeFirstName(int year, const string& first_name)
  80. //////  {
  81. //////      first_names[year]= first_name;
  82. //////  }
  83. //////  void ChangeLastName(int year, const string& last_name)
  84. //////  {
  85. //////      last_names[year]= last_name;
  86. //////  }
  87. //////  string GetFullName(int year)
  88. //////  {
  89. //////      const string first_name = FindNameByYear(first_names,year);
  90. //////      const string last_name = FindNameByYear(last_names,year);
  91. //////
  92. //////      if(first_name.empty()&&last_name.empty())
  93. //////      {
  94. //////          return "Incognito";
  95. //////      }
  96. //////      else if(first_name.empty())
  97. //////      {
  98. //////          return last_name+ " with unknown first name";
  99. //////      }
  100. //////      else if(last_name.empty())
  101. //////      {
  102. //////          return first_name+ " with unknown last name";
  103. //////      }
  104. //////      else
  105. //////      {
  106. //////          return first_name+" "+ last_name;
  107. //////      }
  108. //////  }
  109. //////private:
  110. //////  map<int,string>first_names;
  111. //////  map<int,string>last_names;
  112. //////
  113. //////};
  114. //////
  115. //////int main()
  116. //////{
  117. //////  return 0;
  118. //////}
  119. //////
  120. //////
  121. ////#include <iostream>
  122. ////#include <algorithm>
  123. ////#include <vector>
  124. ////
  125. ////using namespace std;
  126. ////
  127. ////const int NUMBER_COUNT = 1'000'000;
  128. ////
  129. ////const int NUMBER = 7654321;
  130. ////
  131. ////const int QUERY_COUNT = 1'000'000;
  132. ////
  133. ////int main()
  134. ////{
  135. ////    vector<int> v;
  136. ////    for(int i=0;i<NUMBER_COUNT;++i)
  137. ////    {
  138. ////        v.push_back(i*10);
  139. ////    }
  140. ////
  141. ////    {
  142. ////        //LOG_DURATION("lower bound");
  143. ////        for(int i=0; i<QUERY_COUNT;++i)
  144. ////        {
  145. ////            lower_bound(begin(v),end(v),NUMBER);
  146. ////        }
  147. ////    }
  148. ////
  149. ////
  150. ////    {
  151. ////        //LOG_DURATION("find_if");
  152. ////        for(int i=0; i<QUERY_COUNT;++i)
  153. ////        {
  154. ////            find_if(begin(v),end(v),[NUMBER](int y){return y>=NUMBER;});
  155. ////        }
  156. ////    }
  157. ////    return 0;
  158. ////}
  159. ////
  160. //#include"profile.h"
  161. //#include <iostream>
  162. //#include <algorithm>
  163. //#include <deque>
  164. //#include <vector>
  165. //#include <set>
  166. //
  167. //using namespace std;
  168. //
  169. ////int main()
  170. ////{
  171. ////    {
  172. ////        //LOG_DURATION("vector");
  173. ////        vector<int> v;
  174. ////        for(int i=0; i<1'000'000;++i)
  175. ////        {
  176. ////            v.insert(begin(v),1);
  177. ////        }
  178. ////    }
  179. ////
  180. ////
  181. ////    {
  182. ////        //LOG_DURATION("deque");
  183. ////        deque<int> v;
  184. ////        for(int i=0; i<1'000'000;++i)
  185. ////        {
  186. ////            v.insert(begin(v),1);
  187. ////        }
  188. ////
  189. ////        return 0;
  190. ////    }
  191. ////
  192. ////}
  193. //
  194. ////int main()
  195. ////{
  196. ////
  197. ////    set<int> numbers;
  198. ////    for(int i=0; i<3'000'000;++i)
  199. ////    {
  200. ////        numbers.insert(i);
  201. ////    }
  202. ////
  203. ////    const int x = 1'000'000;
  204. ////
  205. ////
  206. ////    {
  207. ////        //LOG_DURATION("global lower_bound");
  208. ////        deque<int> v;
  209. ////        cout<< *lower_bound(begin(numbers),end(numbers),x)<<endl;
  210. ////    }
  211. ////
  212. ////
  213. ////    {
  214. ////        //LOG_DURATION("lower_bound method");
  215. ////        deque<int> v;
  216. ////        cout<< *numbers.lower_bound(x);
  217. ////    }
  218. ////    return 0;
  219. ////
  220. ////}
  221. //
  222. //const int NUMBER_COUNT = 1'000'000;
  223. //const int NUMBER = 7654321;
  224. //const int QUERY_COUNT = 10;
  225. //
  226. //
  227. //int main()
  228. //{
  229. //  vector<int> v;
  230. //  for(int i=0;i<NUMBER_COUNT;++i)
  231. //  {
  232. //      v.push_back(i*10);
  233. //  }
  234. //
  235. //  {
  236. //      //LOG_DURATION("lower bound");
  237. //      for(int i=0; i<QUERY_COUNT;++i)
  238. //      {
  239. //          lower_bound(begin(v),end(v),NUMBER);
  240. //      }
  241. //  }
  242. //
  243. //
  244. //  {
  245. //      //LOG_DURATION("find_if");
  246. //      for(int i=0; i<QUERY_COUNT;++i)
  247. //      {
  248. //          find_if(begin(v),end(v),[NUMBER](int y){return y>=NUMBER;});
  249. //      }
  250. //  }
  251. //  return 0;
  252. //}
  253. //
  254.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement