Advertisement
Guest User

bubble_peja

a guest
Apr 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int para[100000];
  6. map<int,int> mp2, mp;
  7. int pp[100000];
  8. int a[100000],t[100000];
  9. int maxi,pmax1,pmax,p;
  10. int n;
  11.  
  12. void printPrevBigger()
  13. {
  14. stack<int> S;
  15. for (int i=0; i<n; i++)
  16. {
  17. while (!S.empty() && S.top() < a[i])
  18. S.pop();
  19. if (S.empty()){
  20. t[i] = 0;
  21. pmax1 = i;
  22. //pmax = i;
  23. //p = i;
  24. //maxi = 0;
  25. }
  26. else{
  27. t[i] = pp[a[i]] - pp[S.top()];
  28. if(t[i]>maxi){
  29. maxi = t[i];
  30. p = i;
  31. pmax = pmax1;
  32. }
  33. }
  34. S.push(a[i]);
  35.  
  36. }
  37. }
  38.  
  39. int main()
  40. {
  41. int u;
  42. scanf("%d", &u);
  43. //cin >> u;
  44. while(u--){
  45. scanf("%d", &n);
  46. //cin >> u;
  47. //mp.clear();
  48. //mp2.clear();
  49. set<int> st;
  50. pmax1=0;
  51. maxi=0;
  52. pmax=0;
  53. p=0;
  54. for(int i=0; i<n; i++){
  55. //cin >> a[i];
  56. scanf("%d", &a[i]);
  57. pp[a[i]] = i;
  58. }
  59. printPrevBigger();
  60.  
  61. /*for(int i=0; i<n; i++){
  62. if(t[i] == 0){
  63. pmax = i;
  64. p = i;
  65. maxi = 0;
  66. }
  67. /*if(mp[para[i]]) t[i] = mp[a[i]]-mp[para[i]];
  68. else t[i] = 0;
  69. if(t[i]>maxi){
  70. maxi = t[i];
  71. p = i;
  72. }
  73. }*/
  74. //int brojac = 0;
  75. for(int i=pmax; i<p; i++){
  76. /*if(mp[para[i]]) t = mp[a[i]]-mp[para[i]];
  77. else t = 0;
  78. if(mp2[t[i]] == 0){
  79. mp2[t[i]] = 1;
  80. brojac ++;
  81. }*/
  82. st.insert(t[i]);
  83. }
  84. //cout << st.size() << endl;
  85. printf("%d\n", st.size());
  86. }
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement