fork(2) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <cmath>
  5. #include <cstdio>
  6. #include <cstring>
  7. #include <string>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <cstdlib>
  12. using namespace std;
  13. int main() {
  14. // your code goes here
  15. long long int i,n,onee=0;
  16. scanf("%I64d",&n); //printf("%I64d\n",n);
  17. long long int a[n];
  18. vector<long long int> temp;
  19. vector<pair<long long int,long long int>> pos;
  20. for(i=0;i<n;i++) {
  21. scanf("%I64d",&a[i]);
  22. //printf("%I64d ",a[i]);
  23. }
  24. for(i=0;i<n;i++) {
  25. //if found a pair
  26. if(temp.size()>0 && find(temp.begin(),temp.end(),a[i])!=temp.end()) {
  27. pos.push_back(make_pair(onee,i));
  28. temp.clear();
  29. onee=i+1;
  30. }
  31. else {
  32. temp.push_back(a[i]);
  33. }
  34. //printf("%ld\n",onee);
  35. }
  36. if(onee == 0) printf("-1\n");
  37. else if(onee != n) pos[pos.size()-1].second = n-1;
  38. if(pos.size()>0) {
  39. printf("%d\n",pos.size());
  40. for(i=0;i<pos.size();i++) printf("%I64d %I64d\n",pos[i].first+1,pos[i].second+1);
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0s 3468KB
stdin
5
1 2 3 4 1
stdout
-1