fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <vector>
  7. #include <set>
  8. #include <deque>
  9. #include <utility>
  10. #include <cmath>
  11. #include <string>
  12. #include <cstring>
  13. #include <iomanip>
  14. #include <cctype>
  15. #include <algorithm>
  16. #include <numeric>
  17. #define Yellow_Flash \
  18.   ios_base::sync_with_stdio(0); \
  19.   cin.tie(0); \
  20.   cout.tie(0)
  21. #define pi 3.14159265358979323
  22. #define el "\n"
  23. #define ll long long
  24. #define sp ' '
  25. #define MAX INT_MAX
  26. #define MIN INT_MIN
  27.  
  28. using namespace std;
  29. using namespace __gnu_pbds;
  30.  
  31.  
  32.  
  33. int main()
  34. {
  35. #ifndef ONLINE_JUDGE
  36. freopen("input.txt", "r", stdin);
  37. freopen("output.txt", "w", stdout);
  38. #endif
  39. Yellow_Flash;
  40. ll t;
  41. cin >> t;
  42. while(t--){
  43. ll n;
  44. cin >> n;
  45. vector<ll> v(n), beg(n), end(n);
  46. stack<ll> st;
  47. map<ll,ll> ind;
  48. for (int i=0; i<n; ++i) {
  49. cin >> v[i];
  50. ind[v[i]]=i;
  51. }
  52. for(int i=n-1; i>=0; --i){
  53. while(!st.empty() && st.top()>v[i]) st.pop();
  54. if(st.empty()) end[i]=ind[v[i]];
  55. else end[i]=ind[st.top()];
  56. st.push(v[i]);
  57. }
  58. for(int i=0; i<n; ++i){
  59. while(!st.empty() && st.top()>v[i]) st.pop();
  60. if(st.empty()) beg[i]=ind[v[i]];
  61. else beg[i]=ind[st.top()];
  62. st.push(v[i]);
  63. }
  64. ll mx=MIN;
  65. for(int i=0; i<n; ++i){
  66. if (beg[i]==-1 && end[i]==-1){
  67. mx=max(n,mx);
  68. }
  69. else if (beg[i]==-1) {
  70. mx=max(mx,end[i]);
  71. }
  72. else if (end[i]==-1) {
  73. mx=max(mx,n-(beg[i]+1));
  74. }
  75. else {
  76. mx=max(mx,end[i]-(beg[i]+1));
  77. }
  78. cout << beg[i] << sp << end[i] << sp << mx << el;
  79. }
  80. }
  81. return 0;
  82. }
  83. /* Fight not to be the Winner ,but to be the last one to lose */
  84.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty