{"id":692,"date":"2020-03-25T15:06:29","date_gmt":"2020-03-25T07:06:29","guid":{"rendered":"http:\/\/kylelv.com\/?p=692"},"modified":"2020-03-25T15:06:29","modified_gmt":"2020-03-25T07:06:29","slug":"cset-stl","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=692","title":{"rendered":"C:Set &#8212; STL"},"content":{"rendered":"\n<h2 class=\"has-text-align-center wp-block-heading\">C:Set<\/h2>\n\n\n\n<p class=\"has-text-align-center\">\u603b\u65f6\u95f4\u9650\u5236:\u00a05000ms\u00a0\u5185\u5b58\u9650\u5236:\u00a0100000kB<\/p>\n\n\n\n<p>\u63cf\u8ff0<\/p>\n\n\n\n<p>\u73b0\u6709\u4e00\u6574\u6570\u96c6\uff08\u5141\u8bb8\u6709\u91cd\u590d\u5143\u7d20\uff09\uff0c\u521d\u59cb\u4e3a\u7a7a\u3002\u6211\u4eec\u5b9a\u4e49\u5982\u4e0b\u64cd\u4f5c\uff1a<br>add x \u628ax\u52a0\u5165\u96c6\u5408<br>del x \u628a\u96c6\u5408\u4e2d\u6240\u6709\u4e0ex\u76f8\u7b49\u7684\u5143\u7d20\u5220\u9664<br>ask x \u5bf9\u96c6\u5408\u4e2d\u5143\u7d20x\u7684\u60c5\u51b5\u8be2\u95ee<br>\u5bf9\u6bcf\u79cd\u64cd\u4f5c\uff0c\u6211\u4eec\u8981\u6c42\u8fdb\u884c\u5982\u4e0b\u8f93\u51fa\u3002<br>add \u8f93\u51fa\u64cd\u4f5c\u540e\u96c6\u5408\u4e2dx\u7684\u4e2a\u6570<br>del \u8f93\u51fa\u64cd\u4f5c\u524d\u96c6\u5408\u4e2dx\u7684\u4e2a\u6570<br>ask \u5148\u8f93\u51fa0\u62161\u8868\u793ax\u662f\u5426\u66fe\u88ab\u52a0\u5165\u96c6\u5408\uff080\u8868\u793a\u4e0d\u66fe\u52a0\u5165\uff09\uff0c\u518d\u8f93\u51fa\u5f53\u524d\u96c6\u5408\u4e2dx\u7684\u4e2a\u6570\uff0c\u4e2d\u95f4\u7528\u7a7a\u683c\u683c\u5f00\u3002<\/p>\n\n\n\n<p>\u8f93\u5165<\/p>\n\n\n\n<p>\u7b2c\u4e00\u884c\u662f\u4e00\u4e2a\u6574\u6570n\uff0c\u8868\u793a\u547d\u4ee4\u6570\u30020&lt;=n&lt;=100000\u3002<br>\u540e\u9762n\u884c\u547d\u4ee4\uff0c\u5982Description\u4e2d\u6240\u8ff0\u3002<\/p>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<p>\u5171n\u884c\uff0c\u6bcf\u884c\u6309\u8981\u6c42\u8f93\u51fa\u3002<\/p>\n\n\n\n<p>\u6837\u4f8b\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">7\nadd 1\nadd 1\nask 1\nask 2\ndel 2\ndel 1\nask 1<\/pre>\n\n\n\n<p>\u6837\u4f8b\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1\n2\n1 2\n0 0\n0\n2\n1 0<\/pre>\n\n\n\n<p>\u63d0\u793a<\/p>\n\n\n\n<p>Please use STL\u2019s set and multiset to finish the task<\/p>\n\n\n\n<p>set\u6a21\u677f\u7ec3\u4e60<br>\u6ce8\u610f\u9700\u8981\u4f7f\u7528multiset<br>\u8981\u6c42\u7528set\uff0cmap\u8bb0\u5f55\u662f\u5426\u51fa\u73b0\u8fc7\u591a\u5999\u554a\uff08<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;map>\n#include&lt;set>\n#include&lt;list>\n#include&lt;cmath>\n#include&lt;queue>\n#include&lt;cstdio>\n#include&lt;string>\n#include&lt;cstring>\n#include&lt;iostream>\n#include&lt;algorithm>\nusing namespace std;\n#define inf 1000000007\n#define ll long long\n#define N 10010\ninline int rd()\n{\n    int x=0,f=1;char ch=getchar();\n    while(ch&lt;'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}\n    while(ch>='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\n    return x*f;\n}\nint n;\nchar op&#91;10];\nmultiset&lt;int>a,ra;\nint main()\n{\n    n=rd();\n    int x,y;\n    while(n--){\n        scanf(\"%s\",op);\n        if(op&#91;1]=='d'){\/\/add\n            x=rd();\n            a.insert(x);ra.insert(x);\n            printf(\"%lu\\n\",a.count(x));\n        }else if(op&#91;1]=='s'){\/\/ask\n            x=rd();\n            printf(\"%d %lu\\n\",(ra.find(x)==ra.end()?0:1),a.count(x));\n        }else{\/\/del\n            x=rd();\n            printf(\"%lu\\n\",a.count(x));\n            a.erase(a.lower_bound(x),a.upper_bound(x));\n        }\n    }\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>C:Set \u603b\u65f6\u95f4\u9650\u5236:\u00a05000ms\u00a0\u5185\u5b58\u9650\u5236:\u00a0100000kB \u63cf\u8ff0 \u73b0\u6709\u4e00\u6574\u6570\u96c6\uff08\u5141\u8bb8\u6709\u91cd\u590d\u5143\u7d20\uff09\uff0c\u521d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[60],"class_list":["post-692","post","type-post","status-publish","format-standard","hentry","category-70","tag-stl"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=692"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/692\/revisions"}],"predecessor-version":[{"id":693,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/692\/revisions\/693"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}