{"id":17,"date":"2017-03-12T21:51:59","date_gmt":"2017-03-13T02:51:59","guid":{"rendered":"http:\/\/zxi.mytechroad.com\/blog\/?p=17"},"modified":"2017-03-15T17:40:12","modified_gmt":"2017-03-15T22:40:12","slug":"zoj-3612-median","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/zoj\/zoj-3612-median\/","title":{"rendered":"[ZOJ] 3612: Median"},"content":{"rendered":"<pre class=\"lang:c++ decode:true  \">\/\/ 3934633  2017-03-13 10:48:25 Accepted  3612  C++0x 900 540 xxfflower\r\n#include &lt;iostream&gt;\r\n#include &lt;vector&gt;\r\n#include &lt;unordered_map&gt;\r\n#include &lt;algorithm&gt;\r\n#include &lt;queue&gt;\r\n#include &lt;set&gt;\r\nusing namespace std;\r\ntypedef long long int64;\r\n\r\nint main() {\r\n  int t,n,x;\r\n  char op[20];\r\n  cin&gt;&gt;t;\r\n\r\n  while(t--) {\r\n    scanf(\"%d\", &amp;n);\r\n    \r\n    vector&lt;int64&gt; a;\r\n\r\n    while(n--) {\r\n      scanf(\"%s %d\", op, &amp;x);\r\n      auto it = lower_bound(a.begin(), a.end(), x);\r\n\r\n      if(op[0] == 'r') {\r\n        if(it==a.end() || *it != x) {\r\n          puts(\"Wrong!\");\r\n          continue;\r\n        } else {\r\n          a.erase(it);\r\n          if(a.empty()) {\r\n            puts(\"Empty!\");\r\n            continue;\r\n          }\r\n        }\r\n      } else if(op[0] == 'a') {\r\n        a.insert(it, x);\r\n      }\r\n\r\n      if(a.size()%2==1) {\r\n        printf(\"%lld\\n\", a[a.size()\/2]);\r\n      } else {\r\n        int64 ans = a[a.size()\/2-1] + a[a.size()\/2];\r\n        if(ans%2==0) \r\n          printf(\"%lld\\n\", ans\/2);\r\n        else \r\n          printf(\"%.1lf\\n\", ans\/2.0);\r\n      }\r\n    }\r\n  }\r\n\r\n  return 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ 3934633 2017-03-13 10:48:25 Accepted 3612 C++0x 900 540 xxfflower #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;unordered_map&gt; #include &lt;algorithm&gt; #include &lt;queue&gt; #include &lt;set&gt; using namespace std;&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[14,13,11,15,12],"class_list":["post-17","post","type-post","status-publish","format-standard","hentry","category-zoj","tag-binary_search","tag-dynamic","tag-median","tag-sorting","tag-vector","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"predecessor-version":[{"id":20,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/17\/revisions\/20"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}