fork(5) download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <cctype>
  7. #include <stack>
  8. #include <queue>
  9. #include <vector>
  10. #include <map>
  11. #include <sstream>
  12. #include <cmath>
  13. #include <limits>
  14. #include <utility>
  15. #include <iomanip>
  16. #include <set>
  17. #include <numeric>
  18. #include <cassert>
  19. #include <ctime>
  20.  
  21. #define INF_MAX 2147483647
  22. #define INF_MIN -2147483647
  23. #define INF_LL 9223372036854775807LL
  24. #define INF 2000000000
  25. #define PI acos(-1.0)
  26. #define EPS 1e-8
  27. #define LL long long
  28. #define mod 1000000007
  29. #define pb push_back
  30. #define mp make_pair
  31. #define f first
  32. #define s second
  33. #define setzero(a) memset(a,0,sizeof(a))
  34. #define setdp(a) memset(a,-1,sizeof(a))
  35. #define bits(a) __builtin_popcount(a)
  36.  
  37. using namespace std;
  38.  
  39. int m[1000005], L[1000005];
  40.  
  41. int main()
  42. {
  43. //ios_base::sync_with_stdio(0);
  44. //freopen("lca.in", "r", stdin);
  45. //freopen("lca.out", "w", stdout);
  46. int n, x, maxi = 0, mini = INF, ch = -1;
  47. scanf("%d", &n);
  48. for(int i=0;i<n;i++)
  49. {
  50. scanf("%d", &x);
  51. if(m[x] == 0)
  52. {
  53. L[x] = i;
  54. m[x] = 1;
  55. }
  56. else m[x]++;
  57. if(m[x] > maxi)
  58. {
  59. maxi = m[x];
  60. mini = i - L[x] + 1;
  61. ch = L[x] + 1;
  62. }
  63. else if(m[x] == maxi && i - L[x] + 1 < mini)
  64. {
  65. mini = i - L[x] + 1;
  66. ch = L[x] + 1;
  67. }
  68. }
  69. cout << ch << " " << ch + mini - 1;
  70. return 0;
  71. }
Success #stdin #stdout 0s 10912KB
stdin
5
1 1 2 2 1
stdout
1 5