#include <iostream>
#include <string>
#include <iterator>
#include <vector>
#include <set>
#include <ctime>
#include <algorithm>
int main( )
{
using namespace std;
vector< string> vs( 200000 ) ;
for ( int i = 0 ; i < vs.size ( ) ; ++ i)
{
vs[ i] = to_string( i) ;
}
set< string> ss( vs.begin ( ) , vs.end ( ) ) ;
{
cout << "linear search on vector" << endl;
time_t now = clock ( ) ;
auto s = find( vs.begin ( ) , vs.end ( ) , "100000" ) ;
cout << "linear search for \" 100000\" took: "
<< double ( clock ( ) - now) / CLOCKS_PER_SEC << " found " << * s << endl;
}
{
cout << "\n binary search on vector" << endl;
sort( vs.begin ( ) , vs.end ( ) ) ;
time_t now = clock ( ) ;
auto s = binary_search( vs.begin ( ) , vs.end ( ) , "100000" ) ;
cout << "binary search for \" 100000\" took: "
<< double ( clock ( ) - now) / CLOCKS_PER_SEC << " found " << boolalpha << s << endl;
}
{
cout << "\n binary search on set" << endl;
time_t now = clock ( ) ;
auto s = ss.find ( "100000" ) ;
cout << "binary search for \" 100000\" took: "
<< double ( clock ( ) - now) / CLOCKS_PER_SEC << " found " << * s << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8aXRlcmF0b3I+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxjdGltZT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KCmludCBtYWluKCkKewogICAgdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiAgICB2ZWN0b3I8c3RyaW5nPiB2cygyMDAwMDApOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCB2cy5zaXplKCk7ICsraSkKICAgIHsKICAgICAgICB2c1tpXSA9IHRvX3N0cmluZyhpKTsKICAgIH0KCiAgICBzZXQ8c3RyaW5nPiBzcyh2cy5iZWdpbigpLCB2cy5lbmQoKSk7CgogICAgewogICAgICAgIGNvdXQgPDwgImxpbmVhciBzZWFyY2ggb24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