{"id":696,"date":"2020-03-25T16:53:05","date_gmt":"2020-03-25T08:53:05","guid":{"rendered":"http:\/\/kylelv.com\/?p=696"},"modified":"2020-03-25T16:53:05","modified_gmt":"2020-03-25T08:53:05","slug":"gpriority-queue%e7%bb%83%e4%b9%a0%e9%a2%98-stl","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=696","title":{"rendered":"G:priority queue\u7ec3\u4e60\u9898 &#8212; STL"},"content":{"rendered":"\n<h2 class=\"has-text-align-center wp-block-heading\">G:priority queue\u7ec3\u4e60\u9898<\/h2>\n\n\n\n<p class=\"has-text-align-center\">\u603b\u65f6\u95f4\u9650\u5236:\u00a02500ms\u00a0\u5185\u5b58\u9650\u5236:\u00a0131072kB<\/p>\n\n\n\n<p>\u63cf\u8ff0<\/p>\n\n\n\n<p>\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\u6b63\u6574\u6570a\u6bd4\u6b63\u6574\u6570b\u4f18\u5148\u7684\u542b\u4e49\u662f\uff1a<br>*a\u7684\u8d28\u56e0\u6570\u6570\u76ee\uff08\u4e0d\u5305\u62ec\u81ea\u8eab\uff09\u6bd4b\u7684\u8d28\u56e0\u6570\u6570\u76ee\u591a\uff1b<br>*\u5f53\u4e24\u8005\u8d28\u56e0\u6570\u6570\u76ee\u76f8\u7b49\u65f6\uff0c\u6570\u503c\u8f83\u5927\u8005\u4f18\u5148\u7ea7\u9ad8\u3002<br><\/p>\n\n\n\n<p>\u73b0\u5728\u7ed9\u5b9a\u4e00\u4e2a\u5bb9\u5668\uff0c\u521d\u59cb\u5143\u7d20\u6570\u76ee\u4e3a0\uff0c\u4e4b\u540e\u6bcf\u6b21\u5f80\u91cc\u9762\u6dfb\u52a010\u4e2a\u5143\u7d20\uff0c\u6bcf\u6b21\u6dfb\u52a0\u4e4b\u540e\uff0c\u8981\u6c42\u8f93\u51fa\u4f18\u5148\u7ea7\u6700\u9ad8\u4e0e\u6700\u4f4e\u7684\u5143\u7d20\uff0c\u5e76\u628a\u8be5\u4e24\u5143\u7d20\u4ece\u5bb9\u5668\u4e2d\u5220\u9664\u3002<\/p>\n\n\n\n<p>\u8f93\u5165<\/p>\n\n\n\n<p>\u7b2c\u4e00\u884c: num (\u6dfb\u52a0\u5143\u7d20\u6b21\u6570\uff0cnum &lt;= 30)<\/p>\n\n\n\n<p>\u4e0b\u976210*num\u884c\uff0c\u6bcf\u884c\u4e00\u4e2a\u6b63\u6574\u6570n\uff08n &lt; 10000000).<\/p>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<p>\u6bcf\u6b21\u8f93\u516510\u4e2a\u6574\u6570\u540e\uff0c\u8f93\u51fa\u5bb9\u5668\u4e2d\u4f18\u5148\u7ea7\u6700\u9ad8\u4e0e\u6700\u4f4e\u7684\u5143\u7d20\uff0c\u4e24\u8005\u7528\u7a7a\u683c\u95f4\u9694\u3002<\/p>\n\n\n\n<p>\u6837\u4f8b\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1\n10 7 66 4 5 30 91 100 8 9<\/pre>\n\n\n\n<p>\u6837\u4f8b\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">66 5<\/pre>\n\n\n\n<p>\u7ec3\u4e60\u4e00\u4e0b\u624b\u5199cmp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;map>\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 10000010\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 sz&#91;N],prm&#91;N>>3],cnt;\nvoid INIT(){\n    memset(sz,-1,sizeof(sz));\n    for(int i=2;i&lt;N;++i){\n        if(!(~sz&#91;i])) prm&#91;++cnt]=i,sz&#91;i]=0;\n        for(int j=1;j&lt;=cnt;++j){\n            if(prm&#91;j]*i>=N) break;\n            sz&#91;prm&#91;j]*i]=max(sz&#91;i],1);\n            if(i%prm&#91;j]==0) break;\n            ++sz&#91;prm&#91;j]*i];\n        }\n    }\n}\nstruct cmp{\n    bool operator()(int &amp;a, int &amp;b){\n        return sz&#91;a]==sz&#91;b]?a&lt;b:sz&#91;a]&lt;sz&#91;b];\n    }\n};\nint T;\npriority_queue&lt;int,vector&lt;int>,cmp>q;\nint tp&#91;310],tot;\nint main()\n{\n    INIT();\n    T=rd();\n    while(T--){\n        for(int i=0;i&lt;10;++i) q.push(rd());\n        printf(\"%d \",q.top());q.pop();\n        tot=0;\n        while(!q.empty()){\n            tp&#91;++tot]=q.top();\n            q.pop();\n        }\n        printf(\"%d\\n\",tp&#91;tot]);\n        for(int i=1;i&lt;tot;++i) q.push(tp&#91;i]);\n    }\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>G:priority queue\u7ec3\u4e60\u9898 \u603b\u65f6\u95f4\u9650\u5236:\u00a02500ms\u00a0\u5185\u5b58\u9650\u5236:\u00a0131072kB \u63cf\u8ff0 \u6211\u4eec\u5b9a [&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-696","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\/696","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=696"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/696\/revisions"}],"predecessor-version":[{"id":697,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/696\/revisions\/697"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}