Codeforces 1270B 灵感题
For an array aa of integers let's denote its maximal element as max(a)max(a), and minimal as min(a)min(a). We will call an array aa of kk integers interesting if max(a)−min(a)≥kmax(a)−min(a)≥k. For example, array [1,3,4,3][1,3,4,3] isn't interesting as max(a)−min(a)=4−1=3<4max(a)−min(a)=4−1=3<4 while array [7,3,0,4,3][7,3,0,4,3] is as max(a)−min(a)=7−0=7≥5max(a)−min(a)=7−0=7≥5.
You are given an array aa of nn integers. Find some interesting nonempty subarray of aa, or tell that it doesn't exist.
An array bb is a subarray of an array aa if bb can be obtained from aa by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
The first line contains integer number tt (1≤t≤100001≤t≤10000). Then tt test cases follow.
The first line of each test case contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the length of the array.
The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109) — the elements of the array.
It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.
For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in aa.
Otherwise, output "YES" in a separate line. In the next line, output two integers ll and rr (1≤l≤r≤n1≤l≤r≤n) — bounds of the chosen subarray. If there are multiple answers, print any.
You can print each letter in any case (upper or lower).
3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020
NO YES 1 4 NO
In the second test case of the example, one of the interesting subarrays is a=[2,0,1,9]a=[2,0,1,9]: max(a)−min(a)=9−0=9≥4max(a)−min(a)=9−0=9≥4.
/* 只要存在合法字串,那么一定存在长度为2的合法子串 */ #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #define maxn 200010 using namespace std; int a[maxn],n; int main(){ int t; scanf("%d",&t); while(t--){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&a[i]); if(n==1){ puts("NO"); continue; } bool flag=0; for(int i=2;i<=n;i++){ if(abs(a[i]-a[i-1])>=2){ flag=1; puts("YES"); printf("%d %d\n",i-1,i); break; } } if(!flag)puts("NO"); } return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
2017-02-12 2017.2.10测试 藏妹子之处