{"id":321,"date":"2024-03-29T17:34:03","date_gmt":"2024-03-29T09:34:03","guid":{"rendered":"https:\/\/linxce.ink\/?p=321"},"modified":"2024-03-29T17:34:03","modified_gmt":"2024-03-29T09:34:03","slug":"%e7%9f%a9%e9%98%b5%e6%93%8d%e4%bd%9c%e8%bf%90%e7%ae%97","status":"publish","type":"post","link":"https:\/\/linxce.ink\/index.php\/%e7%9f%a9%e9%98%b5%e6%93%8d%e4%bd%9c%e8%bf%90%e7%ae%97\/%e5%85%a8%e9%83%a8\/acm\/","title":{"rendered":"\u77e9\u9635\u64cd\u4f5c\u8fd0\u7b97"},"content":{"rendered":"<p>\u5305\u542b\u77e9\u9635\u52a0\u6cd5\u3001\u51cf\u6cd5\u3001\u4e58\u6cd5\u3001\u5feb\u901f\u5e42\u3001\u6d41\u8f93\u5165\u3001\u6d41\u8f93\u51fa<\/p>\n<pre><code class=\"language-c++\">class mat\n{\npublic:\n    int n, m;\n    vector&lt;vector&lt;int&gt; &gt; a;\n    mat(int n, int m) : n(n), m(m) { a.resize(n + 1, vector&lt;int&gt;(m + 1)); }\n    mat operator+(const mat &amp;T) const\n    {\n        mat res(n, m);\n        for (int i = 1; i &lt;= n; ++i)\n            for (int j = 1; j &lt;= m; ++j)\n                res.a[i][j] = (a[i][j] + T.a[i][j]) % mod;\n        return res;\n    }\n    mat operator-(const mat &amp;T) const\n    {\n        mat res(n, m);\n        for (int i = 1; i &lt;= n; ++i)\n            for (int j = 1; j &lt;= m; ++j)\n                res.a[i][j] = (a[i][j] - T.a[i][j]) % mod;\n        return res;\n    }\n    mat operator*(const mat &amp;T) const\n    {\n        mat res(n, T.m);\n        int r;\n        for (int i = 1; i &lt;= n; ++i)\n            for (int k = 1; k &lt;= m; ++k)\n            {\n                r = a[i][k];\n                for (int j = 1; j &lt;= T.m; ++j)\n                    res.a[i][j] += T.a[k][j] * r, res.a[i][j] %= mod;\n            }\n        return res;\n    }\n    mat operator^(int x) const\n    {\n        mat res(n, n), bas(n, m); \/\/ n == m\n        for (int i = 1; i &lt;= n; ++i)\n            res.a[i][i] = 1;\n        for (int i = 1; i &lt;= n; ++i)\n            for (int j = 1; j &lt;= m; ++j)\n                bas.a[i][j] = a[i][j] % mod;\n        while (x)\n        {\n            if (x &amp; 1)\n                res = res * bas;\n            bas = bas * bas;\n            x &gt;&gt;= 1;\n        }\n        return res;\n    }\n};\nistream &amp;operator&gt;&gt;(istream &amp;is, mat &amp;x)\n{\n    for (int i = 1; i &lt;= x.n; ++i)\n        for (int j = 1; j &lt;= x.m; ++j)\n            is &gt;&gt; x.a[i][j];\n    return is;\n}\nostream &amp;operator&lt;&lt;(ostream &amp;os, const mat &amp;x)\n{\n    for (int i = 1; i &lt;= x.n; ++i)\n    {\n        for (int j = 1; j &lt;= x.m; ++j)\n            os &lt;&lt; x.a[i][j] &lt;&lt; &quot; &quot;;\n        os &lt;&lt; endl;\n    }\n    return os;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5305\u542b\u77e9\u9635\u52a0\u6cd5\u3001\u51cf\u6cd5\u3001\u4e58\u6cd5\u3001\u5feb\u901f\u5e42&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,25,34],"tags":[21,7,37,36,35],"class_list":["post-321","post","type-post","status-publish","format-standard","hentry","category-acm","category-25","category-34","tag-acm","tag-cpp","tag-37","tag-36","tag-35"],"_links":{"self":[{"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/posts\/321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/comments?post=321"}],"version-history":[{"count":1,"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/posts\/321\/revisions"}],"predecessor-version":[{"id":322,"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/posts\/321\/revisions\/322"}],"wp:attachment":[{"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/media?parent=321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/categories?post=321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linxce.ink\/index.php\/wp-json\/wp\/v2\/tags?post=321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}