fork(5) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ms(s,n) memset(s,n,sizeof(s))
  5. #define all(a) a.begin(),a.end()
  6. #define present(t, x) (t.find(x) != t.end())
  7. #define sz(a) int((a).size())
  8. #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
  9. #define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
  10. #define pb push_back
  11. #define pf push_front
  12. #define fi first
  13. #define se second
  14. #define mp make_pair
  15.  
  16. typedef long long ll;
  17. typedef unsigned long long ull;
  18. typedef long double ld;
  19. typedef pair<int,int> pi;
  20. typedef vector<int> vi;
  21. typedef vector<pi> vii;
  22.  
  23. const int MOD = (int) 1e9+7;
  24. const int INF = (int) 1e9+1;
  25. inline ll gcd(ll a,ll b){ll r;while(b){r=a%b;a=b;b=r;}return a;}
  26. inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
  27.  
  28.  
  29. void TC(){
  30. int n; cin >> n;
  31. int a[n];
  32. for(int &x : a) cin >> x;
  33. int l, r;
  34. for(int i = 0; i < n - 1; i++){
  35. if(a[i] > a[i+1]) {
  36. l = i ; break;
  37. }
  38. }
  39. for(int i = n - 1; i > 0; i--){
  40. if(a[i] < a[i-1]){
  41. r = i ; break;
  42. }
  43. }
  44. int min = *min_element(a + l, a + r + 1);
  45. int max = *max_element(a + l, a + r + 1);
  46. for(int i = 0 ; i <= l ; i++){
  47. if(a[i] > min){
  48. l = i ; break;
  49. }
  50. }
  51. for(int i = n - 1; i >= r; i--){
  52. if(a[i] < max){
  53. r = i ; break;
  54. }
  55. }
  56. cout << l + 1 << " " << r + 1 <<endl;
  57. }
  58.  
  59.  
  60. int main(){
  61. //freopen("input.txt","r", stdin);
  62. //freopen("output.txt","w",stdout);
  63. int t; cin >> t;
  64. while(t--){
  65. TC();
  66. }
  67. }
Runtime error #stdin #stdout 0s 5440KB
stdin
Standard input is empty
stdout
Standard output is empty