{"id":1418,"date":"2020-04-22T11:23:04","date_gmt":"2020-04-22T03:23:04","guid":{"rendered":"https:\/\/cf.mnihyc.com\/blog\/?p=1418"},"modified":"2020-04-22T11:23:04","modified_gmt":"2020-04-22T03:23:04","slug":"arc092d-two-sequences","status":"publish","type":"post","link":"https:\/\/cf.mnihyc.com\/blog\/archives\/1418","title":{"rendered":"[ARC092D] Two Sequences"},"content":{"rendered":"<h1 style=\"text-align: center;\"><strong>[ARC092D] Two Sequences<\/strong><\/h1>\n<p style=\"text-align: center;\">Time Limit: 3 sec \/ Memory Limit: 256 MB<\/p>\n<p style=\"text-align: center;\">\u96be\u5ea6\uff1a<span style=\"color: #ffff00;\">\\(4.0\\)<\/span><\/p>\n<ul>\n<li>\n<h3><strong>Problem Statement<\/strong><\/h3>\n<\/li>\n<\/ul>\n<p>You are given two integer sequences, each of length \\(N\\): \\(a_1, \\cdots ,a_N\\) and \\(b_1, \\cdots ,b_N\\).<\/p>\n<p>There are \\(N^2\\) ways to choose two integers \\(i\\) and \\(j\\) such that \\(1 \\leq i,j \\leq N\\). For each of these \\(N^2\\) pairs, we will compute \\(a_i+b_j\\) and write it on a sheet of paper. That is, we will write \\(N^2\\) integers in total.<\/p>\n<p>Compute the XOR of these \\(N^2\\) integers.<\/p>\n<p>\u7ed9\u5b9a\u4e24\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6b63\u6574\u6570\u6570\u7ec4 \\(a,b\\) \uff0c\u6c42 \\(\\forall 1 \\leq i,j \\leq n\\)\uff0c\\(a_i+b_j\\) \u5728\u4e8c\u8fdb\u5236\u4e0b\u7684\u5f02\u6216\u548c \u3002<\/p>\n<ul>\n<li>\n<h3><strong>Input<\/strong><\/h3>\n<\/li>\n<\/ul>\n<p>\\(n\\) \u548c\u4e24\u6570\u7ec4 \\(a,b\\) \u3002<\/p>\n<ul>\n<li>\n<h3><strong>Output<\/strong><\/h3>\n<\/li>\n<\/ul>\n<p><span style=\"color: black;\">\u7b54\u6848\u3002<\/span><\/p>\n<ul>\n<li>\n<h3><strong>Sample Input<\/strong><\/h3>\n<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true \">5\r\n1 2 3 4 5\r\n1 2 3 4 5<\/pre>\n<ul>\n<li>\n<h3><strong>Sample Output<\/strong><\/h3>\n<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true \">2<\/pre>\n<ul>\n<li>\n<h3><strong>Constraints<\/strong><\/h3>\n<\/li>\n<\/ul>\n<p>\\(1 \\leq n \\leq 200000\\)\uff0c\\(1 \\leq a_i,b_j \\leq 2^{28}\\)\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Source\uff1a<a href=\"https:\/\/atcoder.jp\/contests\/arc092\/tasks\/arc092_b\">ARC092D<\/a><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>from orz zzx\uff1a<\/p>\n<p>\u5bf9\u6bcf\u4e00\u4f4d \\(d\\)\uff0c\u6c42\u6709\u591a\u5c11\u5bf9 \\(i,j\\) \u6ee1\u8db3 \\(a_i+b_j\\) \u7684\u7b2c \\(d\\) \u4f4d\u4e3a \\(1\\)\uff0c\u4e5f\u5c31\u662f \\((a_i+b_j) \\bmod 2d+1 \\geq 2d\\)\uff0c\u5355\u8c03\u6027\u626b\u4e00\u626b\u5c31\u884c\u4e86\uff0c\u590d\u6742\u5ea6 \\(O(n(\\log a_i+\\log b_i))\\)\u3002<\/p>\n<p>\u8fd9\u9898\u6bd4\u6211\u5728\u6cc9\u5dde\u96c6\u8bad\u51fa\u7684\u67d0\u4e2a\u9898\u7565\u5fae\u7b80\u5355\u4e00\u70b9\uff0c\u90a3\u4e2a\u9898\u662f\u6c42\u6240\u6709 \\(l \\leq r\\)<br \/>\n\u7684 \\(\\sum\\limits_{i=l}^r a_i\\) \u7684\u5f02\u6216\u548c\uff0c\u601d\u8def\u7c7b\u4f3c\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>from sb mnihyc\uff1a<\/p>\n<p>\u300c\u5355\u8c03\u6027\u626b\u4e00\u626b\u300d\u60f3\u5f97\u4e0d\u662f\u5f88\u6e05\u695a\u7684\u53ef\u4ee5\u76f4\u63a5\u6392\u5e8f+\u4e8c\u5206\u3002<\/p>\n<p>\u5177\u4f53\u6765\u8bf4\u5c31\u662f\uff1a\u679a\u4e3e\u4f4d\uff0c\u8981\u67e5\u627e\u5e8f\u5217\u4e2d\u6709\u591a\u5c11\u4e2a\u6570\u5f53\u524d\u4f4d\u4e3a \\(1\\)\u3002<\/p>\n<p>\u5982\u679c\u8981\u67e5\u627e \\(N\\) \u6b21\u7684\u8bdd\uff0c\u666e\u901a\u67e5\u627e\u7684\u590d\u6742\u5ea6\u5c31\u662f \\(N^2\\)\u3002<\/p>\n<p>\u663e\u7136\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6392\u5e8f\u4f18\u5316\u8fd9\u4e2a\u64cd\u4f5c\u3002<\/p>\n<p>\u5c06\u5176\u4e2d\u4e00\u4e2a\u6570\u7ec4\u6392\u5e8f\u540e\u518d\u67e5\u627e\uff0c\u76ee\u6807\u5c31\u53d8\u6210\u4e86\u6709\u5e8f\u5e8f\u5217\u4e2d\u8fde\u7eed\u7684\u5355\u8c03\u7684\u4e00\u6bb5\uff0c\u4f7f\u7528\u4e8c\u5206\uff0c\u590d\u6742\u5ea6 \\(O(n \\log n)\\)\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true \">    #include &lt;cstdio&gt;\r\n    #include &lt;cstdlib&gt;\r\n    #include &lt;cstring&gt;\r\n    #include &lt;climits&gt;\r\n    #include &lt;algorithm&gt;\r\n     \r\n    #define _max(_a_,_b_) ((_a_)&gt;(_b_)?(_a_):(_b_))\r\n     \r\n    #ifdef ONLINE_JUDGE\r\n    \tchar __B[1&lt;&lt;15],*__S=__B,*__T=__B;\r\n    \t#define getchar() (__S==__T&amp;&amp;(__T=(__S=__B)+fread(__B,1,1&lt;&lt;15,stdin),__S==__T)?EOF:*__S++)\r\n    #endif\r\n    inline int getnum()\r\n    {\r\n    \tregister char c=0;\r\n    \twhile(!(c&gt;='0' &amp;&amp; c&lt;='9'))\r\n    \t\tc=getchar();\r\n    \tregister int a=0;\r\n    \twhile(c&gt;='0' &amp;&amp; c&lt;='9')\r\n    \t\ta=a*10+c-'0',c=getchar();\r\n    \treturn a;\r\n    }\r\n     \r\n    int a[205050],b[205050];\r\n    #define GetLen(_arr,_l,_r) (std::lower_bound(&amp;(_arr)[1],&amp;(_arr)[N+1],_r)-std::lower_bound(&amp;(_arr)[1],&amp;(_arr)[N+1],_l))\r\n    int ta[205050],tb[205050];\r\n     \r\n    int main()\r\n    {\r\n    \tregister int N=getnum(),mxv=0;\r\n    \tfor(register int i=1;i&lt;=N;i++)\r\n    \t\ta[i]=getnum(),mxv=_max(mxv,a[i]);\r\n    \tfor(register int i=1;i&lt;=N;i++)\r\n    \t\tb[i]=getnum(),mxv=_max(mxv,b[i]);\r\n    \tregister unsigned dig=1;\r\n    \twhile(mxv)\r\n    \t\tdig++,mxv&gt;&gt;=1;\r\n    \t\r\n    \tint ans=0,pw2=1;\r\n    \twhile(dig--)\r\n    \t{\r\n    \t\tfor(register int i=1;i&lt;=N;i++)\r\n    \t\t\tta[i]=a[i]&amp;((pw2&lt;&lt;1)-1),tb[i]=b[i]&amp;((pw2&lt;&lt;1)-1);\r\n    \t\tstd::sort(&amp;tb[1],&amp;tb[N+1]);\r\n    \t\tregister bool sum=0;\r\n    \t\tfor(register int i=1;i&lt;=N;i++)\r\n    \t\t\tsum^=GetLen(tb,pw2-ta[i],(pw2&lt;&lt;1)-ta[i])&amp;1,\r\n    \t\t\tsum^=GetLen(tb,pw2+(pw2&lt;&lt;1)-ta[i],(pw2&lt;&lt;2)-ta[i])&amp;1;\r\n    \t\tans|=pw2*sum,pw2&lt;&lt;=1;\r\n    \t}\r\n    \tprintf(\"%d\\n\",ans);\r\n    \t\r\n    \treturn 0;\r\n    }<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ARC092D] Two Sequences Time Limit: 3 sec \/ Memory Limi &hellip; <a href=\"https:\/\/cf.mnihyc.com\/blog\/archives\/1418\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">[ARC092D] Two Sequences<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52,63],"tags":[],"class_list":["post-1418","post","type-post","status-publish","format-standard","hentry","category-mediuma","category-bindivide"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[ARC092D] Two Sequences - mnihyc&#039;s Blog<\/title>\n<meta name=\"description\" content=\"Two Sequences Time Limit: 3 sec \/ Memory Limit: 256 MB \u96be\u5ea6\uff1a Problem Statement You are given two integer sequences, each of length (N): (a_1, cdots\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mnihyc.com\/blog\/archives\/1418\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[ARC092D] Two Sequences - mnihyc&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"Two Sequences Time Limit: 3 sec \/ Memory Limit: 256 MB \u96be\u5ea6\uff1a Problem Statement You are given two integer sequences, each of length (N): (a_1, cdots\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mnihyc.com\/blog\/archives\/1418\" \/>\n<meta property=\"og:site_name\" content=\"mnihyc&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-22T03:23:04+00:00\" \/>\n<meta name=\"author\" content=\"mnihyc\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mnihyc\" \/>\n<meta name=\"twitter:site\" content=\"@mnihyc\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"mnihyc\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mnihyc.com\/blog\/archives\/1418#article\",\"isPartOf\":{\"@id\":\"https:\/\/mnihyc.com\/blog\/archives\/1418\"},\"author\":{\"name\":\"mnihyc\",\"@id\":\"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751\"},\"headline\":\"[ARC092D] Two Sequences\",\"datePublished\":\"2020-04-22T03:23:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mnihyc.com\/blog\/archives\/1418\"},\"wordCount\":183,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751\"},\"articleSection\":[\"4.0 ~ 5.0\",\"\u4e8c\u5206\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/mnihyc.com\/blog\/archives\/1418#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mnihyc.com\/blog\/archives\/1418\",\"url\":\"https:\/\/mnihyc.com\/blog\/archives\/1418\",\"name\":\"[ARC092D] Two Sequences - mnihyc&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/mnihyc.com\/blog\/#website\"},\"datePublished\":\"2020-04-22T03:23:04+00:00\",\"description\":\"Two Sequences Time Limit: 3 sec \/ Memory Limit: 256 MB \u96be\u5ea6\uff1a Problem Statement You are given two integer sequences, each of length \\\\(N\\\\): \\\\(a_1, \\\\cdots\",\"breadcrumb\":{\"@id\":\"https:\/\/mnihyc.com\/blog\/archives\/1418#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mnihyc.com\/blog\/archives\/1418\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mnihyc.com\/blog\/archives\/1418#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/mnihyc.com\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[ARC092D] Two Sequences\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mnihyc.com\/blog\/#website\",\"url\":\"https:\/\/mnihyc.com\/blog\/\",\"name\":\"mnihyc&#039;s Blog\",\"description\":\"Welcome!\",\"publisher\":{\"@id\":\"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mnihyc.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751\",\"name\":\"mnihyc\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8d111f863afc3f98816bc96220f97077d470a96f41088de9f19530fc480f8e72?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8d111f863afc3f98816bc96220f97077d470a96f41088de9f19530fc480f8e72?s=96&d=mm&r=g\",\"caption\":\"mnihyc\"},\"logo\":{\"@id\":\"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[ARC092D] Two Sequences - mnihyc&#039;s Blog","description":"Two Sequences Time Limit: 3 sec \/ Memory Limit: 256 MB \u96be\u5ea6\uff1a Problem Statement You are given two integer sequences, each of length (N): (a_1, cdots","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mnihyc.com\/blog\/archives\/1418","og_locale":"zh_CN","og_type":"article","og_title":"[ARC092D] Two Sequences - mnihyc&#039;s Blog","og_description":"Two Sequences Time Limit: 3 sec \/ Memory Limit: 256 MB \u96be\u5ea6\uff1a Problem Statement You are given two integer sequences, each of length (N): (a_1, cdots","og_url":"https:\/\/mnihyc.com\/blog\/archives\/1418","og_site_name":"mnihyc&#039;s Blog","article_published_time":"2020-04-22T03:23:04+00:00","author":"mnihyc","twitter_card":"summary_large_image","twitter_creator":"@mnihyc","twitter_site":"@mnihyc","twitter_misc":{"\u4f5c\u8005":"mnihyc","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mnihyc.com\/blog\/archives\/1418#article","isPartOf":{"@id":"https:\/\/mnihyc.com\/blog\/archives\/1418"},"author":{"name":"mnihyc","@id":"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751"},"headline":"[ARC092D] Two Sequences","datePublished":"2020-04-22T03:23:04+00:00","mainEntityOfPage":{"@id":"https:\/\/mnihyc.com\/blog\/archives\/1418"},"wordCount":183,"commentCount":0,"publisher":{"@id":"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751"},"articleSection":["4.0 ~ 5.0","\u4e8c\u5206"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mnihyc.com\/blog\/archives\/1418#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mnihyc.com\/blog\/archives\/1418","url":"https:\/\/mnihyc.com\/blog\/archives\/1418","name":"[ARC092D] Two Sequences - mnihyc&#039;s Blog","isPartOf":{"@id":"https:\/\/mnihyc.com\/blog\/#website"},"datePublished":"2020-04-22T03:23:04+00:00","description":"Two Sequences Time Limit: 3 sec \/ Memory Limit: 256 MB \u96be\u5ea6\uff1a Problem Statement You are given two integer sequences, each of length \\(N\\): \\(a_1, \\cdots","breadcrumb":{"@id":"https:\/\/mnihyc.com\/blog\/archives\/1418#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mnihyc.com\/blog\/archives\/1418"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/mnihyc.com\/blog\/archives\/1418#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/mnihyc.com\/blog"},{"@type":"ListItem","position":2,"name":"[ARC092D] Two Sequences"}]},{"@type":"WebSite","@id":"https:\/\/mnihyc.com\/blog\/#website","url":"https:\/\/mnihyc.com\/blog\/","name":"mnihyc&#039;s Blog","description":"Welcome!","publisher":{"@id":"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mnihyc.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/61e167d6d591fdd20dcfee2cf848a751","name":"mnihyc","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8d111f863afc3f98816bc96220f97077d470a96f41088de9f19530fc480f8e72?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8d111f863afc3f98816bc96220f97077d470a96f41088de9f19530fc480f8e72?s=96&d=mm&r=g","caption":"mnihyc"},"logo":{"@id":"https:\/\/mnihyc.com\/blog\/#\/schema\/person\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/cf.mnihyc.com\/blog\/wp-json\/wp\/v2\/posts\/1418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cf.mnihyc.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cf.mnihyc.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cf.mnihyc.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cf.mnihyc.com\/blog\/wp-json\/wp\/v2\/comments?post=1418"}],"version-history":[{"count":0,"href":"https:\/\/cf.mnihyc.com\/blog\/wp-json\/wp\/v2\/posts\/1418\/revisions"}],"wp:attachment":[{"href":"https:\/\/cf.mnihyc.com\/blog\/wp-json\/wp\/v2\/media?parent=1418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cf.mnihyc.com\/blog\/wp-json\/wp\/v2\/categories?post=1418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cf.mnihyc.com\/blog\/wp-json\/wp\/v2\/tags?post=1418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}