fork(1) download
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<map>
  5. using namespace std;
  6.  
  7. multimap<int,int> mymultimap;
  8. multimap<int,int>::iterator it;
  9. pair<multimap<int,int>::iterator,multimap<int,int>::iterator> ret;
  10.  
  11. void tournament(int st,int end,int s[])
  12. {
  13. if(st<end)
  14. {
  15. int mid=(st+end)/2;
  16. tournament(st,mid,s);
  17. tournament(mid+1,end,s);
  18. if(s[st]<s[mid+1])
  19. {
  20. mymultimap.insert (pair<int,int>(s[mid+1],s[st]));
  21. s[st]=s[mid+1];
  22. }
  23. else
  24. mymultimap.insert (pair<int,int>(s[st],s[mid+1]));
  25. }
  26. }
  27.  
  28. int tour(int s[])
  29. {
  30. tournament(0,7,s);
  31. ret=mymultimap.equal_range(s[0]);
  32. it=ret.first;
  33. int max=(*it).second;
  34. it--;
  35. for(;it!=ret.second;++it)
  36. {
  37. if(it->second>max)
  38. max=it->second;
  39. }
  40. return max;
  41. }
  42.  
  43. int main()
  44. {
  45. int i,s[]={3,7,1,4,2,8,5,6};
  46. cout<<tour(s);
  47. return 0;
  48. }
Success #stdin #stdout 0.02s 2856KB
stdin
Standard input is empty
stdout
7