CF1817A Almost Increasing Subsequence 题解
1.CF1909C Heavy Intervals 题解2.CF1913C Game with Multiset 题解3.P9750 [CSP-J 2023] 一元二次方程 题解4.CF1891B Deja Vu 题解5.CF1907B YetnotherrokenKeoard 题解6.CF1913B Swap and Delete 题解7.CF1121A Technogoblet of Fire 题解8.CF1162B Double Matrix 题解9.CF1184B1 The Doctor Meets Vader (Easy) 题解10.CF133B Unary 题解11.P8661 [蓝桥杯 2018 省 B] 日志统计 题解12.P3891 [GDOI2014] 采集资源 题解13.CF1804C Pull Your Luck 题解14.CF1815A Ian and Array Sorting 题解15.CF1681C Double Sort 题解16.P8791 [蓝桥杯 2022 国 AC] 内存空间 题解17.CF1250A Berstagram 题解18.CF358B Dima and Text Messages 题解19.CF1737C Ela and Crickets 题解
20.CF1817A Almost Increasing Subsequence 题解
21.CF1670B Dorms War 题解22.CF121A Lucky Sum 题解23.CF875B Sorting the Coins 题解24.CF158C Cd and pwd commands 题解25.CF1040B Shashlik Cooking 题解26.CF958F1 Lightsabers (easy) 题解题面。
2023.5.18 修正关于前缀和数组的说法,与代码适配的思路。
题意
给定长度为
对于几乎递增的定义:如果一个序列中不存在连续的三个数
思路
用一个前缀和数组
简单做个解释,对于每个
5 4 3 2 1 2 3 4 5 1
在上面的序列中,子序列
5 4(3 2 1) 2 3 4 5 1
也可以是这样的:
(5 4 3) 2 1 2 3 4 5 1
为了区分选择与未被选择,这里用斜体与粗体区分开,选择方法不止两种,上面的第一种选法,与给出的解释一致。
证明
当序列中存在
从第
当
前缀数组(2023.5.18 新增)
对于每一个
代码
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cstring>
#include<algorithm>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#define ll long long
#define inf 0x3f3f3f3f
#define fr(i , a , b) for(ll i = a ; i <= b ; ++i)
#define fo(i , a , b) for(ll i = a ; i >= b ; --i)
#pragma comment(linker , "/stack : 200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
inline char gchar()
{
static char buf[1000000] , *p1 = buf , *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf , 1 , 1000000 , stdin) , p1 == p2) ? EOF : *p1++;
}
inline ll read()
{
ll x = 0 , f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-')
{
f = -1;
}
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
ll n , q , a[200005];
ll l , r;
ll f[200005] , now;
inline ll answer(ll L , ll R)
{
ll ans = f[R] - f[L + 1];
if(R - L + 1 <= 2)//特判,区间长度为2或1
{
ans = 0;
}
return R - L + 1 - ans;
}
signed main()
{
n = read();
q = read();
fr(i , 1 , n)
{
a[i] = read();
if(i >= 3)
{
now = 0;
if(a[i - 2] >= a[i - 1] && a[i - 1] >= a[i])
{
now = 1;
}
f[i] = f[i - 1] + now;
}
}
while(q--)
{
l = read();
r = read();
printf("%lld\n" , answer(l , r));
}
system("pause");
return 0;
}
- 一个好的指挥官不会背叛他的军队,无论代价是什么。
- 一个更好的指挥官知道当他想背叛他的军队时,什么时候应该伪装。
- 一个最好的指挥官精明地确立自己的绝对领导,并引领着人民走向更好的未来。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现