{"id":244,"date":"2026-10-28T11:43:35","date_gmt":"2026-10-28T03:43:35","guid":{"rendered":"https:\/\/bkxiaohei123.xyz\/?p=244"},"modified":"2026-10-28T11:43:37","modified_gmt":"2026-10-28T03:43:37","slug":"%e6%97%a5%e5%b8%b8%e5%86%99%e9%a2%98%ef%bc%9a-almost-increasing-subsequence","status":"publish","type":"post","link":"https:\/\/bkxiaohei123.xyz\/index.php\/2026\/10\/28\/%e6%97%a5%e5%b8%b8%e5%86%99%e9%a2%98%ef%bc%9a-almost-increasing-subsequence\/","title":{"rendered":"\u65e5\u5e38\u5199\u9898\uff1a\u00a0Almost Increasing Subsequence"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/codeforces.com\/contest\/1817\/problem\/A\" data-type=\"link\" data-id=\"https:\/\/codeforces.com\/contest\/1817\/problem\/A\"><strong>\u9898\u76ee\u94fe\u63a5<\/strong><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u597d\u4e45\u6ca1\u5199\u9898\u89e3\u4e86<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9898\u610f\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u6709 <em>n<\/em> \u4e2a\u6570\u7684\u5e8f\u5217\uff0c\u4e14\u7ed9\u51fa q \u4e2a\u8be2\u95ee\uff0c\u6bcf\u6b21\u8be2\u95ee\u533a\u95f4 [<em>l<\/em>,<em>r<\/em>]\uff0c\u95ee\u6b64\u533a\u95f4\u5185\u6700\u957f\u7684\u51e0\u4e4e\u9012\u589e\u5b50\u5e8f\u5217\u957f\u5ea6\u662f\u591a\u5c11\u3002\u6240\u8c13\u51e0\u4e4e\u9012\u589e\u5b50\u5e8f\u5217\u662f\u6307\uff0c\u82e5\u8be5\u5e8f\u5217\u4e2d\u4e0d\u5b58\u5728\u8fde\u7eed\u7684\u4e09\u4e2a\u6570 <em>x<\/em>\uff0c<em>y<\/em>\uff0c<em>z<\/em>\uff0c\u4f7f\u5f97 <em>x<\/em>\u2265<em>y<\/em>\u2265\u00a0<em>z<\/em>\uff0c\u90a3\u4e48\u6b64\u5e8f\u5217\u4e3a\u51e0\u4e4e\u9012\u589e\u5b50\u5e8f\u5217\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9047\u5230\u8fd9\u79cd\u9898\u7b2c\u4e00\u4e2a\u60f3\u5230\u7684\u4e00\u5b9a\u662f<strong>\u524d\u7f00\u548c<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u53ea\u9700\u8bb0\u5f55\u4e0d\u6ee1\u8db3\u51e0\u4e4e\u9012\u589e\u7684\u6570\u5b57\u5373\u53ef<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9a\u4e49\u524d\u7f00\u548c\u6570\u7ec4 <em>s<\/em>[<em>i<\/em>]\uff0c\u8868\u793a\u4ee5 <em>i<\/em> \u7ed3\u5c3e\u7684\uff0c\u5728\u8fd9\u4e4b\u524d\u5171\u6709\u591a\u5c11\u4e2a\u5143\u7d20\u6ee1\u8db3 <em>x<\/em>\u2265<em>y<\/em>\u2265\u00a0<em>z<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>s<\/em>[<em>l<\/em>] \u7531 <em>a<\/em>[<em>l<\/em>\u22121] \u548c <em>a<\/em>[<em>l<\/em>\u22122] \u51b3\u5b9a\uff0c<em>s<\/em>[<em>l<\/em>+1] \u7531 <em>a<\/em>[<em>l<\/em>] \u548c <em>a<\/em>[<em>l<\/em>\u22121] \u51b3\u5b9a\uff0c\u542b\u6709\u4e0d\u5728\u533a\u95f4\u5185\u7684\u5143\u7d20\uff0c\u6240\u4ee5\u7b97\u7684\u65f6\u5019\u5e94\u8be5\u4ece <em>s<\/em>[<em>l<\/em>+2] \u5f00\u59cb\u7b97<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u6709\u4e00\u4e2a\u6ce8\u610f\u7684\u70b9\uff0c\u4ecel\u5230r\u5b9e\u9645\u4e0a\u4e0d\u6ee1\u8db3\u7b54\u6848\u7684\u70b9\u6570\u5e94\u4e3as[r] &#8211; s[l+1]\u800c\u4e0d\u662fs[r] -s[l-1] \uff0c\u8fd9\u662f\u4e3a\u4ec0\u4e48\uff1f\u56e0\u4e3a\u4f60\u63d0\u53d6\u4ecel\u5230r\u7684\u5e8f\u5217\u51fa\u6765\uff0c\u6b64\u65f6l\u4ee5\u53cal+1\u6309\u7167\u4e0a\u6587\u6240\u63cf\u8ff0\u6761\u4ef6\u5fc5\u5b9a\u6ee1\u8db3\u7b54\u6848\uff0c\u56e0\u4e3a\u7b97\u7684\u65f6\u5019\u4eces[l+2]\u5f00\u59cb\u7b97\uff0c\u6240\u4ee5\u7b54\u6848\u4fbf\u662fs[r] &#8211; s[l+2 -1]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u540c\u65f6\u8981\u5224\u65ad\u5f53l\u5230r\u5e8f\u5217\u957f\u5ea6\u5c0f\u4e8e\u7b49\u4e8e2\u65f6\u7684\u7279\u6b8a\u6761\u4ef6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9898\u89e3<\/p>\n\n\n\n<pre class=\"wp-block-code language-cpp\" data-wzcbh-download=\"snippet.cpp\"><code lang=\"cpp\" class=\"language-cpp\">#include&lt;bits\/stdc++.h>\nusing namespace std;\n#define int long long\nint cnt[200050];\nint a[200050];\nvoid resolve(){\n   memset(cnt,0,sizeof(cnt));\n   memset(a,0,sizeof(a));\n  int n,q;\n  cin>>n>>q;\n  for(int i =1 ; i&lt;=n; i++)\n  {\n    cin>>a[i];\n    if(i&lt;3)\n    {\n      continue;\n    }\n    if(a[i-2]>a[i-1]&amp;&amp;a[i-1]>a[i])\n    {\n        cnt[i] = cnt[i-1] + 1;\n    }\n    else\n    cnt[i] = cnt[i-1];\n  }\n  for(int i = 0 ; i&lt;q ; i++)\n  {\n   int l,r;\n   cin>>l>>r;\n   int ans = r - l + 1;\n   if(ans&lt;=2)\n   {\n      cout&lt;&lt;ans&lt;&lt;endl;\n      continue;\n   } \n   cout&lt;&lt;ans - (cnt[r] - cnt[l+1])&lt;&lt;endl;\n  }\n}\nsigned main() {\n\tios::sync_with_stdio(false);\n\tcin.tie(nullptr);\n\tint T;\n\tT=1;\n\twhile (T--)\n\t\tresolve();\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u94fe\u63a5 \u597d\u4e45\u6ca1\u5199\u9898\u89e3\u4e86 \u9898\u610f\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u6709 n \u4e2a\u6570\u7684\u5e8f\u5217\uff0c\u4e14\u7ed9\u51fa q \u4e2a\u8be2\u95ee\uff0c\u6bcf\u6b21\u8be2\u95ee\u533a\u95f4 [l,r]\uff0c\u95ee\u6b64 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":91,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[14,33,13,25],"class_list":["post-244","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learning","tag-c","tag-33","tag-13","tag-25"],"_links":{"self":[{"href":"https:\/\/bkxiaohei123.xyz\/index.php\/wp-json\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bkxiaohei123.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bkxiaohei123.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bkxiaohei123.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bkxiaohei123.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=244"}],"version-history":[{"count":1,"href":"https:\/\/bkxiaohei123.xyz\/index.php\/wp-json\/wp\/v2\/posts\/244\/revisions"}],"predecessor-version":[{"id":245,"href":"https:\/\/bkxiaohei123.xyz\/index.php\/wp-json\/wp\/v2\/posts\/244\/revisions\/245"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bkxiaohei123.xyz\/index.php\/wp-json\/wp\/v2\/media\/91"}],"wp:attachment":[{"href":"https:\/\/bkxiaohei123.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bkxiaohei123.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bkxiaohei123.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}