B. Interesting Subarray
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
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.
Output
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).
Example
input
Copy
3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020
output
Copy
NO YES 1 4 NO
Note
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.
=========================================================================
钻牛角尖的题,k越小越好,那就取2,判断连续两个数字是否是绝对值相差2
- # include
- # include
- # include
- # include
- # include
- using namespace std;
- typedef long long int ll;
-
- int main ()
- {
-
- int t;
-
- cin>>t;
-
- while(t--)
- {
- int n,pre,x,flag=0,ans1,ans2;
- cin>>n>>pre;
-
- for(int i=2;i<=n;i++)
- {
- cin>>x;
-
- if(abs(x-pre)>=2)
- {
- ans1=i-1;
- ans2=i;
- flag=1;
- }
- pre=x;
- }
-
- if(flag)
- {
- cout<<"YES"<
- cout<
" "< - }
- else
- {
- cout<<"NO"<
- }
- }
-
- return 0;
- }
-
相关阅读:
Harris/Shi-Tomasi角点检测
AcWing102. 最佳牛围栏
关于本地项目连接git远程仓库以及git设置ignore文件
c++ 小游戏(2种)
印象深刻的bug汇总(持续更新)
Tomcat环境变量配置教程
HCIP第十三天
谈谈对OceanBase单机分布式一体化的思考
java版工程管理系统Spring Cloud+Spring Boot+Mybatis实现工程管理系统源码
简述React 和 Vue 的 diff 时间复杂度从 O(n^3) 优化 到 O(n) ,那么 O(n^3) 和 O(n) 是如何计算出来的 ?
-
原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126305675