{"id":620,"date":"2017-05-25T20:29:00","date_gmt":"2017-05-25T12:29:00","guid":{"rendered":"http:\/\/kylelv.com\/?p=620"},"modified":"2020-03-04T14:33:03","modified_gmt":"2020-03-04T06:33:03","slug":"bzoj-2179-fft%e5%bf%ab%e9%80%9f%e5%82%85%e7%ab%8b%e5%8f%b6-fft","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=620","title":{"rendered":"bzoj 2179: FFT\u5feb\u901f\u5085\u7acb\u53f6 &#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-69fdeefe58cdf\" 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-69fdeefe58cdf\"  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=620\/#2179_FFT%E5%BF%AB%E9%80%9F%E5%82%85%E7%AB%8B%E5%8F%B6\" title=\"2179: FFT\u5feb\u901f\u5085\u7acb\u53f6\">2179: FFT\u5feb\u901f\u5085\u7acb\u53f6<\/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=620\/#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=620\/#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=620\/#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=620\/#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=620\/#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=620\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"2179_FFT%E5%BF%AB%E9%80%9F%E5%82%85%E7%AB%8B%E5%8F%B6\"><\/span>2179: FFT\u5feb\u901f\u5085\u7acb\u53f6<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>\u7ed9\u51fa\u4e24\u4e2an\u4f4d10\u8fdb\u5236\u6574\u6570x\u548cy\uff0c\u4f60\u9700\u8981\u8ba1\u7b97x*y\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\u6b63\u6574\u6570n\u3002 \u7b2c\u4e8c\u884c\u63cf\u8ff0\u4e00\u4e2a\u4f4d\u6570\u4e3an\u7684\u6b63\u6574\u6570x\u3002 \u7b2c\u4e09\u884c\u63cf\u8ff0\u4e00\u4e2a\u4f4d\u6570\u4e3an\u7684\u6b63\u6574\u6570y\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\u51fa\u4e00\u884c\uff0c\u5373x*y\u7684\u7ed3\u679c\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>1<br>3<br>4<\/p>\n\n\n\n<p><\/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>12<\/p>\n\n\n\n<p>\u6570\u636e\u8303\u56f4\uff1a<br>n&lt;=60000<\/p>\n\n\n\n<p><\/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<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 ll long long\n#define PI acos(-1)\n#define N 200010\nint n,m,c&#91;N],L=-1,r&#91;N];\ncp a&#91;N],b&#91;N];\nchar s1&#91;N],s2&#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;j+k+i];\n                x&#91;j+k]=X+Y;x&#91;j+k+i]=X-Y;\n            }\n        }\n    }\n}\nint main()\n{\n    scanf(\"%d%s%s\",&amp;n,s1,s2);n--;\n    for(int i=0;i&lt;=n;i++) a&#91;i]=s1&#91;n-i]-'0';\n    for(int i=0;i&lt;=n;i++) b&#91;i]=s2&#91;n-i]-'0';\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=0;i&lt;=m;i++) c&#91;i]=(int)(a&#91;i].real()\/n+0.1);\n    for(int i=0;i&lt;=m;i++)\n    {\n        if(c&#91;i]>9)\n        {\n            c&#91;i+1]+=c&#91;i]\/10;\n            c&#91;i]%=10;if(i==m)m++;\n        }\n    }\n    for(int i=m;i>=0;i--) printf(\"%d\",c&#91;i]);\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>2179: FFT\u5feb\u901f\u5085\u7acb\u53f6 Time Limit:&nbsp;10 Sec&nbsp;&nbsp;Memor [&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,19],"class_list":["post-620","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-fft","tag-19"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/620","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=620"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/620\/revisions"}],"predecessor-version":[{"id":621,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/620\/revisions\/621"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}