Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Feb 22nd, 2013  |  syntax: C++  |  size: 0.89 KB  |  hits: 4  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <string>
  5. #include <sstream>
  6. #include <map>
  7. #include <list>
  8. #include <queue>
  9. #include <set>
  10. #include <algorithm>
  11. #include <climits>
  12. #include <cmath>
  13. #include <cassert>
  14. #include <stack>
  15. #include <bitset>
  16. #include <tr1/unordered_map>
  17. #include <tr1/unordered_set>
  18.  
  19. #define mp make_pair
  20. #define ll long long
  21. #define ull unsigned long long
  22.  
  23. const int INF=(INT_MAX>>2);
  24.  
  25. using namespace std;
  26. int a[100000];
  27. int f[100000+1];
  28. int main() {
  29. //      freopen("me.txt","r",stdin);
  30.         //freopen("out.txt","w",stdout);
  31.         int n,k;
  32.         cin>>n>>k;
  33.         for(int i=0;i<n;cin>>a[i++]) ;
  34.         int nusf=0;
  35.         int r1=0,r2=-1;
  36.         for(int i=0;i<n && r2==-1;++i) {
  37.                 ++f[a[i]];
  38.                 nusf+=(f[a[i]]==1);
  39.                 if(nusf==k) r2=i;
  40.         }
  41.         if(r1!=-1) for(;f[a[r1]]>1;++r1) --f[a[r1]];
  42.         if(r2!=-1) cout<<(r1+1)<<" "<<(r2+1);
  43.         if(r2==-1) puts("-1 -1");
  44.     return 0;
  45. }