{"id":624,"date":"2017-05-25T11:24:49","date_gmt":"2017-05-25T03:24:49","guid":{"rendered":"http:\/\/kylelv.com\/?p=624"},"modified":"2020-03-04T14:37:56","modified_gmt":"2020-03-04T06:37:56","slug":"bzoj-2194-%e5%bf%ab%e9%80%9f%e5%82%85%e7%ab%8b%e5%8f%b6%e4%b9%8b%e4%ba%8c-fft","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=624","title":{"rendered":"bzoj 2194: \u5feb\u901f\u5085\u7acb\u53f6\u4e4b\u4e8c &#8212; FFT"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fdef8819d0d\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fdef8819d0d\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.kylelv.com\/?p=624\/#2194_%E5%BF%AB%E9%80%9F%E5%82%85%E7%AB%8B%E5%8F%B6%E4%B9%8B%E4%BA%8C\" title=\"2194: \u5feb\u901f\u5085\u7acb\u53f6\u4e4b\u4e8c\">2194: \u5feb\u901f\u5085\u7acb\u53f6\u4e4b\u4e8c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.kylelv.com\/?p=624\/#Description\" title=\"Description\">Description<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.kylelv.com\/?p=624\/#Input\" title=\"Input\">Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.kylelv.com\/?p=624\/#Output\" title=\"Output\">Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.kylelv.com\/?p=624\/#Sample_Input\" title=\"Sample Input\">Sample Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.kylelv.com\/?p=624\/#Sample_Output\" title=\"Sample Output\">Sample Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.kylelv.com\/?p=624\/#HINT\" title=\"HINT\">HINT<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.kylelv.com\/?p=624\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"2194_%E5%BF%AB%E9%80%9F%E5%82%85%E7%AB%8B%E5%8F%B6%E4%B9%8B%E4%BA%8C\"><\/span>2194: \u5feb\u901f\u5085\u7acb\u53f6\u4e4b\u4e8c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"has-text-align-center\">Time Limit:&nbsp;10 Sec&nbsp;&nbsp;Memory Limit:&nbsp;259 MB<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u8bf7\u8ba1\u7b97C[k]=sigma(a[i]*b[i-k]) \u5176\u4e2d k &lt; = i &lt; n \uff0c\u5e76\u4e14\u6709 n &lt; = 10 ^ 5\u3002 a,b\u4e2d\u7684\u5143\u7d20\u5747\u4e3a\u5c0f\u4e8e\u7b49\u4e8e100\u7684\u975e\u8d1f\u6574\u6570\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u7b2c\u4e00\u884c\u4e00\u4e2a\u6574\u6570N,\u63a5\u4e0b\u6765N\u884c\uff0c\u7b2ci+2..i+N-1\u884c\uff0c\u6bcf\u884c\u4e24\u4e2a\u6570\uff0c\u4f9d\u6b21\u8868\u793aa[i],b[i] (0 &lt; = i &lt; N)\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u8f93\u51faN\u884c\uff0c\u6bcf\u884c\u4e00\u4e2a\u6574\u6570\uff0c\u7b2ci\u884c\u8f93\u51faC[i-1]\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>5<br>3 1<br>2 4<br>1 1<br>2 4<br>1 4<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>24<br>12<br>10<br>6<br>1<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Source\"><\/span>Source<span class=\"ez-toc-section-end\"><\/span><\/h2>\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;complex>\n#include&lt;cstring>\n#include&lt;iostream>\n#include&lt;algorithm>\nusing namespace std;\n#define cp complex&lt;double>\n#define inf 1000000007\n#define ll long long\n#define PI acos(-1)\n#define N 400010\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}\ncp a&#91;N],b&#91;N];\nint c&#91;N],n,m,L=-1,r&#91;N];\nvoid FFT(cp *x,int f)\n{\n    for(int i=0;i&lt;n;i++) if(i&lt;r&#91;i]) swap(x&#91;i],x&#91;r&#91;i]]);\n    for(int i=1;i&lt;n;i&lt;&lt;=1)\n    {\n        cp wn(cos(PI\/i),f*sin(PI\/i));\n        for(int j=0;j&lt;n;j+=(i&lt;&lt;1))\n        {\n            cp w(1,0),X,Y;\n            for(int k=0;k&lt;i;k++,w*=wn)\n            {\n                X=x&#91;j+k];Y=w*x&#91;i+j+k];\n                x&#91;j+k]=X+Y;x&#91;i+j+k]=X-Y;\n            }\n        }\n    }\n}\nint main()\n{\n    n=rd()-1;\n    for(int i=0;i&lt;=n;i++){a&#91;i]=rd();b&#91;n-i]=rd();}\n    m=n&lt;&lt;1;for(n=1;n&lt;=m;n&lt;&lt;=1) L++;\n    for(int i=0;i&lt;n;i++) r&#91;i]=(r&#91;i>>1]>>1)|((i&amp;1)&lt;&lt;L);\n    FFT(a,1);FFT(b,1);\n    for(int i=0;i&lt;n;i++) a&#91;i]*=b&#91;i];\n    FFT(a,-1);\n    for(int i=m\/2;i&lt;=m;i++) printf(\"%d\\n\",(int)(a&#91;i].real()\/n+0.1));\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>2194: \u5feb\u901f\u5085\u7acb\u53f6\u4e4b\u4e8c Time Limit:&nbsp;10 Sec&nbsp;&nbsp;Memory [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[38],"class_list":["post-624","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-fft"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/624","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=624"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/624\/revisions"}],"predecessor-version":[{"id":625,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/624\/revisions\/625"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}