{"id":2975,"date":"2025-01-29T03:04:05","date_gmt":"2025-01-29T03:04:05","guid":{"rendered":"https:\/\/histy.jp\/?p=2975"},"modified":"2025-01-30T02:56:32","modified_gmt":"2025-01-30T02:56:32","slug":"post-2975","status":"publish","type":"post","link":"https:\/\/histy.jp\/?p=2975","title":{"rendered":"\u7af6\u6280\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u9244\u5247\u3092C#\u3067\u89e3\u3044\u3066\u307f\u305f\u3002A06\u7de8"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u76ee\u7684<\/h2>\n\n\n\n<p>Atcoder\u306b\u63b2\u8f09\u3055\u308c\u3066\u3044\u308b\u300c\u7af6\u6280\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u9244\u5247\u300d\u3092\u89e3\u3044\u3066\u3001\u4ed6\u306e\u4eba\u3068\u56de\u7b54\u3092\u6bd4\u3079\u306a\u304c\u3089\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3068C#\u306b\u95a2\u3059\u308b\u77e5\u8b58\u3092\u5b66\u3093\u3067\u3044\u304f\u3053\u3068\u3092\u76ee\u7684\u3068\u3057\u305f\u8a18\u4e8b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u554f\u984c<\/h2>\n\n\n\n<p><a href=\"https:\/\/atcoder.jp\/contests\/tessoku-book\/tasks\/math_and_algorithm_ai\">Atcoder\u30da\u30fc\u30b8<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8003\u3048\u65b9<\/h3>\n\n\n\n<p>\u307e\u305a\u306f\u554f\u984c\u6587\u3092\u7406\u89e3\u3059\u308b\u3002<br>\u8cea\u554f\u304cQ\u500b\u6e21\u3055\u308c\u3066\u3001\u305d\u308c\u305e\u308c\u306b\u7b54\u3048\u308c\u3070OK\u3002<br>\u5404\u8cea\u554f\u5185\u5bb9\u306f\u958b\u50ac\u3055\u308c\u305f\u30a4\u30d9\u30f3\u30c8\u306e\u7279\u5b9a\u671f\u9593\u306b\u3069\u308c\u304f\u3089\u3044\u6765\u5834\u8005\u6570\u304c\u3042\u3063\u305f\u304b\u3092\u805e\u304b\u308c\u308b\u3002<\/p>\n\n\n\n<p>\u6700\u521d\u306f\u30b7\u30f3\u30d7\u30eb\u306b\u5168\u63a2\u7d22\u3059\u308b\u65b9\u6cd5\u3092\u8003\u3048\u3066\u307f\u308b\u3002<br>\u8cea\u554f\u3054\u3068\u306b\u6765\u5834\u8005\u6570\u3092\u958b\u59cb\u65e5\u304b\u3089\u7d42\u4e86\u65e5\u307e\u3067\u8db3\u3057\u3066\u3001\u305d\u306e\u5024\u3092\u51fa\u529b\u3059\u308b\u308c\u3070OK\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Linq;\nclass Program\n{\n    static void Main(string&#91;] args)\n    {\n        int&#91;] nq = Console.ReadLine().Split(' ').Select(i =&gt; int.Parse(i)).ToArray();\n        int n = nq&#91;0];\n        int q = nq&#91;1];\n        int&#91;] a = Console.ReadLine().Split(' ').Select(i =&gt; int.Parse(i)).ToArray();\n\n        for (int i = 0; i &lt; q; i++)\n        {\n            int&#91;] lr = Console.ReadLine().Split(' ').Select(j =&gt; int.Parse(j)).ToArray();\n            int sum = 0;\n\n            for(int k = lr&#91;0]; k &lt;= lr&#91;1]; k++)\n            {\n                sum += a&#91;k - 1]; \/\/ 0-index\u306a\u306e\u30671\u65e5\u76ee\u306e\u6765\u5834\u8005\u6570\u306f1-1=0\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002\n            }\n            Console.WriteLine(sum);\n        }\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>\u305f\u3060\u3057\u3001<br>\u30fbN\u304c\u6700\u5927\u306710\u306e5\u4e57<br>\u30fbQ\u304c\u6700\u5927\u306710\u306e5\u4e57<br>\u306a\u306e\u3067\u3001L\u304c1\u3001R\u304c100000\u306e\u6642TLE\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<p>\u3046\u30fc\u3093\u3001\u56f0\u3063\u305f\u3002\u3053\u308c\u3092\u89e3\u6d88\u3059\u308b\u305f\u3081\u306b\u6765\u52dd\u8005\u6570\u3092\u8a08\u7b97\u3059\u308b\u51e6\u7406(\u8a08\u7b97\u91cf\u304cn)\u3092\u3069\u3046\u306b\u304b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u50d5\u304c\u66f8\u3044\u305f\u305f\u30b3\u30fc\u30c9<\/h3>\n\n\n\n<p>\u6765\u5834\u8005\u6570\u3092\u7d2f\u7a4d\u548c\u3067\u914d\u5217\u306b\u3042\u3089\u304b\u3058\u3081\u6301\u3063\u3066\u304a\u304f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Linq;\nclass Program\n{\n    static void Main(string&#91;] args)\n    {\n        int&#91;] nq = Console.ReadLine().Split(' ').Select(i =&gt; int.Parse(i)).ToArray();\n        int n = nq&#91;0];\n        int q = nq&#91;1];\n        int&#91;] a = Console.ReadLine().Split(' ').Select(i =&gt; int.Parse(i)).ToArray();\n\n        for (int i = 1; i &lt; n; i++)\n        {\n            a&#91;i] += a&#91;i - 1];\n        }\n\n        for (int i = 0; i &lt; q; i++)\n        {\n            int&#91;] lr = Console.ReadLine().Split(' ').Select(j =&gt; int.Parse(j)).ToArray();\n            if (lr&#91;0] == 1)\n            {\n                Console.WriteLine(a&#91;lr&#91;1] - 1]);\n            }\n            else\n            {\n                Console.WriteLine(a&#91;lr&#91;1] - 1] - a&#91;lr&#91;0] - 2]);\n            }\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u51fa\u529b\u90e8\u5206\u306eif\u6587\u3092<a href=\"https:\/\/learn.microsoft.com\/ja-jp\/dotnet\/csharp\/language-reference\/operators\/conditional-operator\">\u4e09\u9805\u6761\u4ef6\u6f14\u7b97\u5b50<\/a>\u3067\u7f6e\u304d\u63db\u3048\u3066\u3082OK\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Linq;\nclass Program\n{\n    static void Main(string&#91;] args)\n    {\n        int&#91;] nq = Console.ReadLine().Split(' ').Select(i =&gt; int.Parse(i)).ToArray();\n        int n = nq&#91;0];\n        int q = nq&#91;1];\n        int&#91;] a = Console.ReadLine().Split(' ').Select(i =&gt; int.Parse(i)).ToArray();\n\n        for (int i = 1; i &lt; n; i++)\n        {\n            a&#91;i] += a&#91;i - 1];\n        }\n\n        for (int i = 0; i &lt; q; i++)\n        {\n            int&#91;] lr = Console.ReadLine().Split(' ').Select(j =&gt; int.Parse(j)).ToArray();\n            int result = (a&#91;lr&#91;1] - 1]) - (lr&#91;0] == 1 ? 0 : a&#91;lr&#91;0] - 2]);\n            Console.WriteLine(result);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u6761\u4ef6\u5206\u5c90\u3092\u3057\u305f\u304f\u306a\u3044\u5834\u5408\u306f\u7d2f\u7a4d\u548c\u3092\u6c42\u3081\u308b\u6bb5\u968e\u30670\u65e5\u76ee\u3092\u4f5c\u3063\u3066\u3001\u5408\u8a08\u6765\u5834\u8005\u6570\u30920\u4eba\u306b\u3057\u3066\u304a\u3051\u3070OK\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Linq;\nclass Program\n{\n    static void Main(string&#91;] args)\n    {\n        int&#91;] nq = Console.ReadLine().Split(' ').Select(i =&gt; int.Parse(i)).ToArray();\n        int n = nq&#91;0];\n        int q = nq&#91;1];\n        int&#91;] a = Console.ReadLine().Split(' ').Select(i =&gt; int.Parse(i)).ToArray();\n        int&#91;] sum = new int&#91;n + 1]; \/\/\u6765\u5834\u8005\u6570\u306e\u7d2f\u7a4d\u548c\n        sum&#91;0] = 0;\n\n        for (int i = 1; i &lt;= n; i++)\n        {\n            \/\/sum&#91;i]\u306fi\u65e5\u76ee\u307e\u3067\u306e\u7d2f\u7a4d\u6765\u5834\u8005\u6570\n            \/\/a&#91;i]\u306f0-index\u306a\u306e\u3067\u3001i+1\u65e5\u76ee\u306e\u6765\u5834\u8005\u6570\u3002\n            \/\/a\u914d\u5217\u306f0-index\u306a\u306e\u3067-1\n            sum&#91;i] = sum&#91;i - 1] + a&#91;i - 1];\n        }\n\n        for (int i = 0; i &lt; q; i++)\n        {\n            int&#91;] lr = Console.ReadLine().Split(' ').Select(j =&gt; int.Parse(j)).ToArray();\n            Console.WriteLine(sum&#91;lr&#91;1]] - sum&#91;lr&#91;0] - 1]);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><\/h3>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u7684 Atcoder\u306b\u63b2\u8f09\u3055\u308c\u3066\u3044\u308b\u300c\u7af6\u6280\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u9244\u5247\u300d\u3092\u89e3\u3044\u3066\u3001\u4ed6\u306e\u4eba\u3068\u56de\u7b54\u3092\u6bd4\u3079\u306a\u304c\u3089\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3068C#\u306b\u95a2\u3059\u308b\u77e5\u8b58\u3092\u5b66\u3093\u3067\u3044\u304f\u3053\u3068\u3092\u76ee\u7684\u3068\u3057\u305f\u8a18\u4e8b\u3002 \u554f\u984c Atcoder\u30da\u30fc\u30b8 \u8003\u3048\u65b9 \u307e\u305a\u306f\u554f\u984c\u6587\u3092\u7406\u89e3\u3059 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"_links":{"self":[{"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/posts\/2975"}],"collection":[{"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/histy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2975"}],"version-history":[{"count":6,"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/posts\/2975\/revisions"}],"predecessor-version":[{"id":2986,"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/posts\/2975\/revisions\/2986"}],"wp:attachment":[{"href":"https:\/\/histy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/histy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/histy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}