Advertisement
Guest User

Untitled

a guest
Jan 21st, 2016
2,899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define forn(i, n) for (int i = 0; i < int(n); i++)
  4. #define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
  5. #define fore(i, l, r) for (int i = int(l); i < int(r); i++)
  6. #define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
  7. #define all(a) (a).begin(), (a).end()
  8. #define sz(a) int((a).size())
  9. #define pb(a) push_back(a)
  10. #define mp(x, y) make_pair((x), (y))
  11. #define x first
  12. #define y second
  13.  
  14. using namespace std;
  15.  
  16. typedef long long li;
  17. typedef long double ld;
  18. typedef pair<int, int> pt;
  19.  
  20. template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
  21. template<typename X> inline X sqr(const X& a) { return a * a; }
  22.  
  23. const int INF = int(1e9);
  24. const li INF64 = li(1e18);
  25. const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;
  26.  
  27. const int N = 300300;
  28.  
  29. int n, a[N];
  30.  
  31. inline bool read() {
  32.     if (!(cin >> n)) return false;
  33.     forn(i, n) assert(scanf("%d", &a[i]) == 1);
  34.     return true;
  35. }
  36.  
  37. inline void solve() {
  38.     vector<pt> ans;
  39.     for (int i = 0, j = 0; i < n; i = j) {
  40.         set<int> used;
  41.         while (j < n && !used.count(a[j])) {
  42.             used.insert(a[j++]);
  43.         }
  44.         if (j == n) break;
  45.         ans.pb(mp(i, j));
  46.         j++;
  47.     }
  48.  
  49.     if (ans.empty()) {
  50.         puts("-1");
  51.         return;
  52.     }
  53.  
  54.     ans.back().y = max(ans.back().y, n - 1);
  55.  
  56.     cout << sz(ans) << endl;
  57.     forn(i, sz(ans)) printf("%d %d\n", ans[i].x + 1, ans[i].y + 1);
  58. }
  59.  
  60. int main() {
  61. #ifdef SU1
  62.     assert(freopen("input.txt", "rt", stdin));
  63.     //assert(freopen("output.txt", "wt", stdout));
  64. #endif
  65.    
  66.     cout << setprecision(10) << fixed;
  67.     cerr << setprecision(5) << fixed;
  68.  
  69.     while (read()) {
  70.         solve();
  71.         //break;
  72.     }
  73.    
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement