{"id":238,"date":"2023-05-17T21:56:48","date_gmt":"2023-05-17T13:56:48","guid":{"rendered":"https:\/\/solost.cn\/?p=238"},"modified":"2023-05-17T21:56:48","modified_gmt":"2023-05-17T13:56:48","slug":"359","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=238","title":{"rendered":"Codeforces Round 576 (Div. 1) &#8211; B. Welfare State"},"content":{"rendered":"<h2>\u9898\u76ee\u94fe\u63a5<\/h2>\n<p><a href=\"https:\/\/codeforces.com\/problemset\/problem\/1198\/B\">\u94fe\u63a5<\/a><\/p>\n<h2>\u9898\u76ee\u5927\u610f<\/h2>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3an\u7684\u6570\u5217\uff0c\u6709\u4e24\u4e2a\u64cd\u4f5c\uff0c1\u64cd\u4f5c\u628a\u7b2cc\u4e2a\u5143\u7d20\u6539\u6210x\uff0c2\u64cd\u4f5c\u628a\u6570\u5217\u6240\u6709\u5c0f\u4e8ex\u7684\u6570\u6539\u6210x<\/p>\n<h2>\u9898\u89e3<\/h2>\n<p>\u6709\u4e24\u79cd\u5199\u6cd5\u3002<\/p>\n<h3>\u7b2c\u4e00\u79cd<\/h3>\n<p>\u7b80\u5355\u7248\u672c\uff0c\u6bcf\u4e2a\u5143\u7d20\u53ea\u6709\u4e24\u79cd\u60c5\u51b5\uff0c\u5982\u679c\u53ea\u67092\u60c5\u51b5\uff0c\u90a3\u4ed6\u7684\u503c\u7684\u5927\u5c0f\u5c31\u662f\u672c\u8eab\u5927\u5c0f\u548c2\u64cd\u4f5c\u6700\u5927\u6539\u7684\u6570\u4e24\u8005\u4e4b\u95f4\u7684\u6700\u5927\u503c\uff0c\u56e0\u4e3a\u6bd4\u4ed6\u5c0f\u7684\u90fd\u6539\u4e0d\u4e86\u5b83\u3002\u5982\u679c\u67091\u64cd\u4f5c\uff0c\u90a3\u8ba9\u7684\u503c\u7684\u5927\u5c0f\u5c31\u662f\u6700\u540e\u4e00\u6b211\u64cd\u4f5c\u548c\u6700\u540e\u4e00\u6b211\u64cd\u4f5c\u4ee5\u540e\u7684\u6700\u59272\u64cd\u4f5c\u7684\u5927\u7684\u90a3\u4e2a\u3002<\/p>\n<pre><code class=\"lang-cpp\">#include &lt;map&gt;\n#include &lt;set&gt;\n#include &lt;cmath&gt;\n#include &lt;queue&gt;\n#include &lt;stack&gt;\n#include &lt;vector&gt;\n#include &lt;bitset&gt;\n#include &lt;cstdio&gt;\n#include &lt;cstdlib&gt;\n#include &lt;cstring&gt;\n#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n#include &lt;algorithm&gt;\n#include &lt;unordered_map&gt;\n#include &lt;unordered_set&gt;\n\n#define x first\n#define y second\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair&lt;ll, ll&gt; pll;\ntypedef pair&lt;int, int&gt; pii;\ntypedef unsigned long long ull;\n\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 2e5 + 10;\n\nint n, m;\nint a[N], s[N];\nvector&lt;pii&gt; q[N];\n\nvoid solve()\n{\n    cin &gt;&gt; n;\n    for(int i = 1; i &lt;= n; i++)\n        cin &gt;&gt; a[i];\n    cin &gt;&gt; m;\n    for(int i = 1; i &lt;= m; i++) {\n        int op;\n        cin &gt;&gt; op;\n        if(op == 1){\n            int c, x;\n            cin &gt;&gt; c &gt;&gt; x;\n            q[c].push_back({i, x});\n        }\n        else{\n            cin &gt;&gt; s[i];\n        }\n    }\n    for(int i = m - 1; i &gt;= 1; i--){\n        s[i] = max(s[i], s[i + 1]);\n    }\n    for(int i = 1; i &lt;= n; i++){\n        if(q[i].empty()){\n            cout &lt;&lt; max(a[i], s[1]) &lt;&lt; &quot; &quot;;\n        }\n        else{\n            auto &amp;t = q[i].back();\n            cout &lt;&lt; max(t.y, s[t.x]) &lt;&lt; &quot; &quot;;\n        }\n    }\n    cout &lt;&lt; endl;\n}\nint main()\n{\n    \/\/ IOS;\n    int t = 1;\n    \/\/ cin &gt;&gt; t;\n    while (t--) {\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n<h3>\u7b2c\u4e8c\u79cd<\/h3>\n<p>\u9009\u62e9\u7ebf\u6bb5\u6811\u5199\u6cd5\uff0c\u61d2\u6807\u8bb0\u7ef4\u62a4\u6700\u5c0f\u503c\uff0c\u5982\u679c\u4e00\u4e2a\u6570\u90fd\u5c0f\u4e8e\u8fd9\u6bb5\u6570\u7684\u6700\u5c0f\u503c\uff0c\u90a3\u5b83\u5c31\u6ca1\u6709\u5fc5\u8981\u5f80\u4e0b\u4f20\u9012<\/p>\n<pre><code class=\"lang-cpp\">#include &lt;algorithm&gt;\n#include &lt;bitset&gt;\n#include &lt;cmath&gt;\n#include &lt;cstdio&gt;\n#include &lt;cstdlib&gt;\n#include &lt;cstring&gt;\n#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n#include &lt;map&gt;\n#include &lt;queue&gt;\n#include &lt;set&gt;\n#include &lt;stack&gt;\n#include &lt;unordered_map&gt;\n#include &lt;unordered_set&gt;\n#include &lt;vector&gt;\n\n#define x first\n#define y second\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair&lt;ll, ll&gt; pll;\ntypedef pair&lt;int, int&gt; pii;\ntypedef unsigned long long ull;\n\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 2e5 + 10;\n\nstruct node {\n    int l, r, val, lazy;\n} tr[4 * N];\nint a[N];\n\nvoid pushup(int u)\n{\n    tr[u].val = min(tr[u &lt;&lt; 1].val, tr[u &lt;&lt; 1 | 1].val);\n}\n\nvoid pushdown(int u)\n{\n    auto &amp;root = tr[u], &amp;l = tr[u &lt;&lt; 1], &amp;r = tr[u &lt;&lt; 1 | 1];\n    if (root.lazy) {\n        l.val = max(l.val, root.lazy);\n        r.val = max(r.val, root.lazy);\n        l.lazy = max(l.lazy, root.lazy);\n        r.lazy = max(r.lazy, root.lazy);\n        root.lazy = 0;\n    }\n}\n\nvoid build(int u, int l, int r)\n{\n    if (l == r) {\n        tr[u] = { l, r, a[l], 0 };\n    } else {\n        tr[u] = { l, r };\n        int mid = (l + r) &gt;&gt; 1;\n        build(u &lt;&lt; 1, l, mid);\n        build(u &lt;&lt; 1 | 1, mid + 1, r);\n        pushup(u);\n    }\n}\n\nvoid modify(int u, int val)\n{\n    tr[u].val = max(tr[u].val, val);\n    tr[u].lazy = max(tr[u].lazy, val);\n}\n\nvoid modify(int u, int l, int r, int val)\n{\n    if (tr[u].l == tr[u].r) {\/\/\u53ea\u6709\u7b49\u4e8e\u8fd9\u4e2a\u5143\u7d20\u672c\u8eab\u7684\u65f6\u5019\u8fd4\u56de\n        tr[u].val = val;\n        return;\n    }\n    pushdown(u);\n    int mid = (tr[u].l + tr[u].r) &gt;&gt; 1;\n    if (l &lt;= mid)\n        modify(u &lt;&lt; 1, l, r, val);\/\/\u6ce8\u610f\u8fb9\u754cl,r\u4e0d\u53d8\n    if (r &gt; mid)\n        modify(u &lt;&lt; 1 | 1, l, r, val);\n    pushup(u);\n}\n\nint query(int u, int l, int r)\n{\n    if (tr[u].l == tr[u].r) {\/\/\u53ea\u6709\u7b49\u4e8e\u8fd9\u4e2a\u5143\u7d20\u672c\u8eab\u7684\u65f6\u5019\u8fd4\u56de\n        return tr[u].val;\n    }\n    pushdown(u);\n    int mid = (tr[u].l + tr[u].r) &gt;&gt; 1;\n    if (l &lt;= mid)\n        return query(u &lt;&lt; 1, l, r);\/\/\u6ce8\u610f\u8fb9\u754cl,r\u4e0d\u53d8\n    if (r &gt; mid)\n        return query(u &lt;&lt; 1 | 1, l, r);\n}\n\nvoid solve()\n{\n    int n, m;\n    cin &gt;&gt; n;\n    for (int i = 1; i &lt;= n; i++)\n        cin &gt;&gt; a[i];\n    build(1, 1, n);\n    cin &gt;&gt; m;\n    for (int i = 1; i &lt;= m; i++) {\n        int op;\n        cin &gt;&gt; op;\n        if (op == 1) {\n            int c, x;\n            cin &gt;&gt; c &gt;&gt; x;\n            modify(1, c, c, x);\n        } else {\n            int x;\n            cin &gt;&gt; x;\n            modify(1, x);\n        }\n    }\n    for (int i = 1; i &lt;= n; i++) {\n        cout &lt;&lt; query(1, i, i) &lt;&lt; &quot; &quot;;\n    }\n    cout &lt;&lt; endl;\n}\nint main()\n{\n    IOS;\n    int t = 1;\n    \/\/ cin &gt;&gt; t;\n    while (t--) {\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u94fe\u63a5 \u94fe\u63a5 \u9898\u76ee\u5927\u610f \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3an\u7684\u6570\u5217\uff0c\u6709\u4e24\u4e2a\u64cd\u4f5c\uff0c1\u64cd\u4f5c\u628a\u7b2cc\u4e2a\u5143\u7d20\u6539\u6210x\uff0c2\u64cd\u4f5c\u628a\u6570\u5217\u6240\u6709\u5c0f\u4e8ex\u7684\u6570\u6539\u6210x \u9898\u89e3 \u6709\u4e24\u79cd\u5199\u6cd5\u3002 \u7b2c\u4e00\u79cd \u7b80\u5355\u7248\u672c\uff0c\u6bcf\u4e2a\u5143\u7d20\u53ea\u6709\u4e24\u79cd\u60c5\u51b5\uff0c\u5982\u679c\u53ea\u67092\u60c5\u51b5\uff0c\u90a3\u4ed6\u7684\u503c\u7684\u5927\u5c0f\u5c31\u662f\u672c\u8eab\u5927\u5c0f\u548c2\u64cd\u4f5c\u6700\u5927\u6539\u7684\u6570\u4e24\u8005\u4e4b\u95f4\u7684\u6700\u5927\u503c\uff0c\u56e0\u4e3a\u6bd4\u4ed6\u5c0f\u7684\u90fd\u6539\u4e0d\u4e86\u5b83\u3002\u5982\u679c\u67091\u64cd\u4f5c\uff0c\u90a3\u8ba9\u7684\u503c\u7684\u5927\u5c0f\u5c31\u662f\u6700\u540e\u4e00\u6b211\u64cd\u4f5c\u548c\u6700\u540e\u4e00\u6b211\u64cd\u4f5c\u4ee5\u540e\u7684\u6700\u59272\u64cd\u4f5c\u7684\u5927\u7684\u90a3\u4e2a\u3002 #include &lt;map&gt; #include &lt;set&gt; #include &lt;cmath&gt; #include &lt;queue&gt; #include &lt;stack&gt; #include &lt;vector&gt; #include &lt;bitset&gt; #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;unordered_map&gt; #include &lt;unordered_set&gt; #define x first #define y second #define endl &#039;\\n&#039; #define IOS \\ ios_base::sync_with_stdio(0); \\ cin.tie(0); \\ cout.tie(0); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[5,49,7],"class_list":["post-238","post","type-post","status-publish","format-standard","hentry","category-solution","tag-5","tag-49","tag-7"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=238"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/238\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}