{"id":417,"date":"2018-08-06T15:19:43","date_gmt":"2018-08-06T15:19:43","guid":{"rendered":"https:\/\/www.haoyuan.info\/?p=417"},"modified":"2018-08-06T15:20:49","modified_gmt":"2018-08-06T15:20:49","slug":"hdu-6345-%e5%ad%90%e4%b8%b2%e6%9f%a5%e8%af%a2","status":"publish","type":"post","link":"https:\/\/haoyuan.info\/?p=417","title":{"rendered":"HDU 6345 \u5b50\u4e32\u67e5\u8be2"},"content":{"rendered":"<h2>\u9898\u610f<\/h2>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u5b57\u7b26\u4e32s<br \/>\n\u6709q\u4e2a\u8be2\u95ee\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u8be2\u95ee\u6709l,r\uff0c\u95ee\u7684\u662f\u5728\u533a\u95f4$[l,r]$\u4e2d\u5b57\u5178\u5e8f\u6700\u5c0f\u5b50\u4e32\u7684\u4e2a\u6570\u3002<\/p>\n<h2>\u9898\u89e3<\/h2>\n<p>\u6613\u8bc1\u5b57\u5178\u5e8f\u6700\u5c0f\u5b50\u4e32\u4e00\u5b9a\u662f\u4e00\u4e2a\u5b57\u6bcd\uff0c\u4e8e\u662f\u53ea\u9700\u8981\u7edf\u8ba1\u5728[l,r]\u8303\u56f4\u5185\u6700\u5c0f\u7684\u5b57\u6bcd\u51fa\u73b0\u7684\u6b21\u6570\u3002<\/p>\n<p>\u7531\u4e8e\u6ca1\u6709\u66f4\u65b0\u64cd\u4f5c\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u5904\u7406\u51fa26\u4e2a\u5b57\u6bcd\u7684\u524d\u7f00\u548c\u3002<br \/>\n\u65f6\u95f4\u590d\u6742\u5ea6$\\mathcal O(26 * |S|)$<\/p>\n<p>\u5982\u679c\u7528\u79bb\u7ebf\u7ef4\u62a4\u67e5\u8be2\u7684\u6700\u5927\u6700\u5c0f\u503c\u6765\u51cf\u5c11\u524d\u7f00\u548c\u7684\u7ef4\u62a4\u6b21\u6570\uff0c\u5728\u8be5\u9898\u7684\u6570\u636e\u8303\u56f4\u8fd8\u53ef\u4ee5\u7701\u4e0b\u4e00\u90e8\u5206\u65f6\u95f4<\/p>\n<p>\u7528fastio\u53ef\u4ee5\u7701\u90e8\u5206\u8f93\u5165\u8f93\u51fa\u65f6\u95f4\uff0c\u524d\u7f00\u548c\u7528short\u4ee3\u66ffint\u53ef\u4ee5\u7701\u4e00\u90e8\u5206\u7a7a\u95f4\u548c\u65f6\u95f4<\/p>\n<h2>AC\u4ee3\u7801<\/h2>\n<pre><code class=\"language-cpp  line-numbers\">#pragma GCC optimize(\"O3\")\n\n#include &lt;iostream&gt;\n#include &lt;cstdio&gt;\n#include &lt;cstring&gt;\n#include &lt;list&gt;\n#include &lt;cmath&gt;\n#include &lt;algorithm&gt;\n#include &lt;vector&gt;\n#include &lt;map&gt;\n#include &lt;queue&gt;\n#include &lt;stack&gt;\n#include &lt;set&gt;\n#include &lt;complex&gt;\n\n#define wl(x) while(x)\n#define bl bool\n#define rtn return\n#define ope operator\n#define cst const\n#define it int\n#define cr char\n#define il inline\n#define tpl template\n#define cl class\n#define db double\n#define sf(x) sizeof(x)\ntypedef long long ll;\nusing namespace std;\nconst int INF = 0x3f3f3f3f;\n\n\/*\n * \u8f93\u5165\u6302\n * \u573a\u573aAK buff\n *\/\n\nclass endln {\n};\n\n\nclass iofstream {\nprivate:\n    int idx;\n    bool eof;\n    char buf[100005], *ps, *pe;\n    char bufout[100005], outtmp[50], *pout, *pend;\n\n    inline void rnext() {\n        if (++ps == pe)\n            pe = (ps = buf) + fread(buf, sf(cr), sf(buf) \/ sf(cr), stdin), eof = true;\n        if (ps == pe)\n            eof = false;\n    }\n\n    inline void write() {\n        fwrite(bufout, sf(cr), pout - bufout, stdout);\n        pout = bufout;\n    }\n\npublic:\n    iofstream(char *in = NULL, char *out = NULL) : idx(-1), eof(true) {\n        ps = buf, pe = buf + 1;\n        pout = bufout, pend = bufout + 100005;\n        if (in)\n            freopen(in, \"r\", stdin);\n        if (out)\n            freopen(out, \"w\", stdout);\n    }\n\n    ~iofstream() {\n        write();\n    }\n\n    tpl&lt;cl T&gt;\n    il bl fin(T &amp;ans) {\n#ifdef ONLINE_JUDGE\n        ans = 0;\n        T f = 1;\n        if (ps == pe) {\n            eof = false;\n            rtn false;\/\/EOF\n        }\n        do {\n            rnext();\n            if ('-' == *ps) f = -1;\n        } wl(!isdigit(*ps) &amp;&amp; ps != pe);\n        if (ps == pe) {\n            eof = false;\n            rtn false;\/\/EOF\n        }\n        do {\n            ans = (ans &lt;&lt; 1) + (ans &lt;&lt; 3) + *ps - 48;\n            rnext();\n        } wl(isdigit(*ps) &amp;&amp; ps != pe);\n        ans *= f;\n#else\n        cin &gt;&gt; ans;\n#endif\n        rtn true;\n    }\n\n    tpl&lt;cl T&gt;\n    il bl fdb(T &amp;ans) {\n#ifdef ONLINE_JUDGE\n        ans = 0;\n        T f = 1;\n        if (ps == pe) rtn false;\/\/EOF\n        do {\n            rnext();\n            if ('-' == *ps) f = -1;\n        } wl(!isdigit(*ps) &amp;&amp; ps != pe);\n        if (ps == pe) rtn false;\/\/EOF\n        do {\n            ans = ans * 10 + *ps - 48;\n            rnext();\n        } wl(isdigit(*ps) &amp;&amp; ps != pe);\n        ans *= f;\n        if (*ps == '.') {\n            rnext();\n            T small = 0;\n            do {\n                small = small * 10 + *ps - 48;\n                rnext();\n            } wl(isdigit(*ps) &amp;&amp; ps != pe);\n            wl(small &gt;= 1) {\n                small \/= 10;\n            }\n            ans += small;\n        }\n#else\n            cin &gt;&gt; ans;\n#endif\n        rtn true;\n    }\n\n\/*\n * \u8f93\u51fa\u6302\n * \u8d85\u5f3a \u8d85\u5feb\n *\/\n\n    il bl out_char(cst cr c) {\n#ifdef ONLINE_JUDGE\n        *(pout++) = c;\n        if (pout == pend) write();\n            \/\/write();\n#else\n            cout &lt;&lt; c;\n#endif\n        rtn true;\n    }\n\n    il bl out_str(cst cr *s) {\n#ifdef ONLINE_JUDGE\n        wl(*s) {\n            *(pout++) = *(s++);\n            if (pout == pend) write();\n        }\n        \/\/write();\n#else\n        cout &lt;&lt; s;\n#endif\n        rtn true;\n    }\n\n    tpl&lt;cl T&gt;\n    il bl out_double(T x, it idx) {\n        char str[50];\n        string format = \"%\";\n        if (~idx) {\n            format += '.';\n            format += (char) (idx + '0');\n        }\n        format += \"f\";\n        sprintf(str, format.c_str(), x);\n        out_str(str);\n    }\n\n    tpl&lt;cl T&gt;\n    il bl out_int(T x) {\n#ifdef ONLINE_JUDGE\n        if (!x) {\n            out_char('0');\n            rtn true;\n        }\n        if (x &lt; 0) x = -x, out_char('-');\n        it len = 0;\n        wl(x) {\n            outtmp[len++] = x % 10 + 48;\n            x \/= 10;\n        }\n        outtmp[len] = 0;\n        for (it i = 0, j = len - 1; i &lt; j; ++i, --j) swap(outtmp[i], outtmp[j]);\n        out_str(outtmp);\n#else\n        cout &lt;&lt; x;\n#endif\n        rtn true;\n    }\n\n    tpl&lt;cl T&gt;\n    il bl out_intln(T x) {\n#ifdef ONLINE_JUDGE\n        out_int(x), out_char('\\n');\n        \/\/write();\n#else\n        cout &lt;&lt; x &lt;&lt; endl;\n#endif\n        rtn true;\n    }\n\n    tpl&lt;cl T&gt;\n    il bl out_doubleln(T x, it idx) {\n        out_double(x, idx), out_char('\\n');\n    }\n\n    il iofstream &amp;ope&lt;&lt;(cst db &amp;x) {\n        out_double(x, idx);\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&lt;&lt;(cst it &amp;x) {\n        out_int(x);\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&lt;&lt;(cst unsigned long long &amp;x) {\n        out_int(x);\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&lt;&lt;(cst unsigned &amp;x) {\n        out_int(x);\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&lt;&lt;(cst long &amp;x) {\n        out_int(x);\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&lt;&lt;(cst ll &amp;x) {\n        out_int(x);\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&lt;&lt;(cst endln &amp;x) {\n        out_char('\\n');\n        rtn *this;\n    }\n\n\n    il iofstream &amp;ope&lt;&lt;(cst cr *x) {\n        out_str(x);\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&lt;&lt;(cst string &amp;x) {\n        out_str(x.c_str());\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&lt;&lt;(cst char &amp;x) {\n        out_char(x);\n        rtn *this;\n    }\n\n    il bl setw(it x) {\n        if (x &gt;= 0) {\n            idx = x;\n            rtn true;\n        }\n        rtn false;\n    }\n\n    il iofstream &amp;ope&gt;&gt;(it &amp;x) {\n        if (!fin(x))eof = false;\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&gt;&gt;(ll &amp;x) {\n        if (!fin(x))eof = false;\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&gt;&gt;(db &amp;x) {\n        if (!fdb(x))eof = false;\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&gt;&gt;(float &amp;x) {\n        if (!fdb(x))eof = false;\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&gt;&gt;(unsigned &amp;x) {\n        if (!fin(x))eof = false;\n        rtn *this;\n    }\n\n    il iofstream &amp;ope&gt;&gt;(unsigned long long &amp;x) {\n        if (!fin(x))eof = false;\n        rtn *this;\n    }\n\n    il ope bl() {\n        rtn eof;\n    }\n\n    il cr getchar() {\n#ifdef ONLINE_JUDGE\n        if (ps == pe) {\n            eof = false;\/\/EOF\n            rtn 0;\n        }\n        rnext();\n        if (ps + 1 == pe)\n            eof = false;\n        rtn *ps;\n#else\n        rtn std::getchar();\n#endif\n    }\n\n    il iofstream &amp;ope&gt;&gt;(char *str) {\n#ifdef ONLINE_JUDGE\n        if (ps == pe) {\n            eof = false;\/\/EOF\n            rtn *this;\n        }\n        do {\n            rnext();\n        } wl(isspace(*ps) &amp;&amp; iscntrl(*ps) &amp;&amp; ps != pe);\n        if (ps == pe) {\n            eof = false;\/\/EOF\n            rtn *this;\n        }\n        do {\n            *str = *ps;\n            ++str;\n            rnext();\n        } wl(!(isspace(*ps) || iscntrl(*ps)) &amp;&amp; ps != pe);\n        *str = '\\0';\n        rtn *this;\n#else\n        cin &gt;&gt; str;\n        rtn *this;\n#endif\n    }\n\n    il iofstream &amp;ope&gt;&gt;(string &amp;str) {\n#ifdef ONLINE_JUDGE\n        str.clear();\n        if (ps == pe) {\n            eof = false;\/\/EOF\n            rtn *this;\n        }\n        do {\n            rnext();\n        } wl(isspace(*ps) &amp;&amp; iscntrl(*ps) &amp;&amp; ps != pe);\n        if (ps == pe) {\n            eof = false;\/\/EOF\n            rtn *this;\n        }\n        do {\n            str += *ps;\n            rnext();\n        } wl(!(isspace(*ps) || iscntrl(*ps)) &amp;&amp; ps != pe);\n        rtn *this;\n#else\n        cin &gt;&gt; str;\n        rtn *this;\n#endif\n    }\n\n    il iofstream &amp;getline(char *str) {\n#ifdef ONLINE_JUDGE\n        if (ps == pe) {\n            eof = false;\/\/EOF\n            rtn *this;\n        }\n        do {\n            rnext();\n            *str = *ps;\n        } while (*ps != '\\n' &amp;&amp; ps != pe &amp;&amp; str++);\n        *str = '\\0';\n        rtn *this;\n#else\n        gets(str);\n        rtn *this;\n#endif\n    }\n\n    il bl endfile() {\n        rtn eof;\n    }\n};\n\nstatic iofstream fin;\nstatic endln ln;\nusing namespace std;\nconst int maxn = 1e5 + 6;\nshort bin[26][maxn];\nchar s[maxn];\npair&lt;int, int&gt; qu[maxn];\n\nint main() {\n    int T;\n    fin &gt;&gt; T;\n    int n, q;\n    for (int kase = 1;kase &lt;= T;++kase) {\n        fin &lt;&lt; \"Case #\" &lt;&lt; kase &lt;&lt; \":\" &lt;&lt; \"\\n\" &gt;&gt; n &gt;&gt; q &gt;&gt; s;\n        int mx = -1, mn = INF;\n        for (int i = 0; i &lt; q; ++i) {\n            fin &gt;&gt; qu[i].first &gt;&gt; qu[i].second;\n            mx = max(mx, qu[i].second);\n            mn = min(mn, qu[i].first);\n        }\n        for (int i = mn - 1; i &lt; mx; ++i) {\n            for (auto &amp;j : bin) {\n                j[i + 1] = j[i];\n            }\n            ++bin[s[i] - 'A'][i + 1];\n        }\n        for (int i = 0; i &lt; q; ++i) {\n            int tot = 0;\n            for (auto j : bin) {\n                tot = j[qu[i].second] - j[qu[i].first - 1];\n                if (tot)break;\n            }\n            fin &lt;&lt; tot &lt;&lt; \"\\n\";\n        }\n\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u610f \u5bf9\u4e8e\u4e00\u4e2a\u5b57\u7b26\u4e32s \u6709q\u4e2a\u8be2\u95ee\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u8be2\u95ee\u6709l,r\uff0c\u95ee\u7684\u662f\u5728\u533a\u95f4$[l,r]$\u4e2d\u5b57\u5178\u5e8f\u6700\u5c0f\u5b50\u4e32\u7684\u4e2a\u6570\u3002  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[39,22],"tags":[],"class_list":["post-417","post","type-post","status-publish","format-standard","hentry","category-c","category-22"],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8UC2c-6J","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=417"}],"version-history":[{"count":0,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/417\/revisions"}],"wp:attachment":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}