C. Find B
1.C. Insert and Equalize2.C. Removal of Unattractive Pairs3.D. Jumping Through Segments4.E. Good Triples5.F. Shift and Reverse6.D. Yet Another Monster Fight7.A. Constructive Problems8.C. Game with Multiset9.A. Rating Increase10.B. Swap and Delete11.A. Problemsolving Log12.B. Preparing for the Contest13.C. Quests14.D. Three Activities15.E2. Game with Marbles (Hard Version)16.cf刷题有感17.A. Anonymous Informant18.A. Forked!19.B. Make Almost Equal With Mod20.C. Heavy Intervals21.D. Split Plus K22.A. 202323.B. Two Divisors24.C. Training Before the Olympiad25.D. Mathematical Problem26.F. Greetings27.C. Partitioning the Array28.G. Bicycles29.E. Eat the Chip30.G. Lights31.D. Array Repetition32.D. Berserk Monsters33.E. Increasing Subsequences34.D. Very Different Array35.G. Mischievous Shooter36.B. Plus-Minus Split37.B. A Balanced Problemset38.C. Did We Get Everything Covered39.D. Find the Different Ones!40.C. Grouping Increases41.D. Good Trip42.C. Physical Education Lesson43.E. Final Countdown44.D. Divisible Pairs45.G. Vlad and Trouble at MIT46.A. Brick Wall47.B. Minimize Inversions48.C. XOR-distance49.A. Moving Chips50.B. Monsters Attack!
51.C. Find B
52.D. Slimes53.C. Turtle Fingers: Count the Values of k54.D. Turtle Tenacity: Continual Mods55.D. Vlad and Division56.C. LR-remainders57.D. Lonely Mountain Dungeons题解
给定数组c,和若干查询区间,请问能否改变区间中的每一个值且区间和还不变?
对于任意一个数,不是加就是减,而对于整个数组而言,加了多少就要减多少
而对于等于1的元素而言,只能加,因此我们令元素为1的为待加元素,其他元素均为待减元素
找出所有大于1的元素把他们变成一,然后差值累加到一个变量sum里
再判断1的个数k,看看sum能否补齐k的缺口,即sum>=k
如果k=0,即没有待加元素,但是指定任意一个元素为待加元素
那就判断区间大小是否大于等于2,即加和减的元素至少各有一个
code
#define ll long long
#include<bits/stdc++.h>
using namespace std;
ll pres[300005]={0};
ll add[300005]={0};
inline void read(ll &x) {
x = 0;
ll flag = 1;
char c = getchar();
while(c < '0' || c > '9'){
if(c == '-')flag = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
x *= flag;
}
inline void write(ll x)
{
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
int main()
{
ll t;
read(t);
while(t--)
{
ll n,q;
read(n); read(q);
for(ll i=1;i<=n;i++)
{
ll x;
read(x);
pres[i]=pres[i-1]+x-1;//区间和
add[i]=add[i-1]+(x==1);//区间1的个数
}
while(q--)
{
ll x,y;
read(x); read(y);
ll k=add[y]-add[x-1],sum=pres[y]-pres[x-1];
if(k&&sum>=k||!k&&y-x+1>=2) puts("YES");
else puts("NO");
}
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~