区间

mac2026-10-06  0

链接:https://ac.nowcoder.com/acm/contest/558/E 来源:牛客网  

时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld

题目描述

小猫在研究序列。

小猫在研究单调性。

给定一个长度为N的序列a1,a2,…,aN,请你选出一个最长的区间[l,r](1≤l≤r≤N),满足al≤al+1≤…≤ar。

如果有多个,请输出l最小的。

输入描述:

第一行一个正整数T,表示数据组数。 每组数据的第一行一个正整数N。 接下来一行N个正整数a1,a2,…,aN。

输出描述:

T行,每行两个正整数l,r,表示选出的区间。

示例1

输入

复制

4 5 1 2 3 4 5 5 5 4 3 2 1 5 5 3 4 1 2 5 3 4 5 1 2

输出

复制

1 5 1 1 2 3 1 3

备注:

1≤T,N,ai≤1000 #include <iostream> #include <algorithm> #include <string.h> #include <string> #include <math.h> #include <list> #include <set> using namespace std; int main(){ ios::sync_with_stdio(false); int n; cin>>n; for(int i=0;i<n;i++){ int m; cin>>m; int a[m]; for(int j=0;j<m;j++){ cin>>a[j]; } int cnt = 0, left = 0; for(int j=0;j<m;j++){ int temp = a[j]; int k = j + 1; while(k<m && temp<=a[k]){ temp = a[k]; k++; } if((k-1)-j > cnt){ left = j; cnt = (k-1)-j; } } cout<<left+1<<" "<<left+cnt+1<<endl; } return 0; }

 

最新回复(0)