Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric> //accumulate
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
#define TEST //*******************************************************************************************************************************************

//?????????????????¨??§?????\\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
#ifdef TEST
#define dout cout
#else
stringstream dummy; //???????????°??????dout?????????????????????????????????
#define dout                                                                   \\
  dummy.str("");                                                               \\
  dummy.clear(stringstream::goodbit);                                          \\
  dummy // dummy?????????????????????????????????????????¨?????¢?????¢???????????????
//???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§????????????????????????????????????
//http://d.hatena.ne.jp/linden/20060427/p1
#endif

int main(void) {

  int N;
  cin >> N;

  string command;
  string str;

  unordered_map<string, int> mp;

  for (int i = 0; i < N; i++) {
    cin >> command >> str;

    if (command[0] == 'i') {
      mp[str] = 1;
    } else if (command[0] == 'f') {
      cout << (mp[str] ? "yes" : "no") << endl;
    }
  }

  //    vector<string> dictionary;
  //    vector<string>::iterator v;
  //
  //    for(int i=0; i<N; i++) {
  //        cin >> command >> str;
  //
  //        if(command[0]=='i') {
  //            dictionary.push_back(str); //??????
  //
  //            v = dictionary.begin();
  //            while(*v < str) v++;
  //
  //            if( v!=dictionary.end() ) {
  //                dictionary.insert(v, str);
  //                dictionary.pop_back(); //????????????
  //            }
  //
  ////            //display dictionary
  ////            for (vector<string>::iterator v=dictionary.begin();
  ///v!=dictionary.end(); v++) dout<<*v<<" "; /            dout << endl;
  //
  //        }
  //        else if(command[0]=='f') {
  //            ans = 0;
  //            for (v=dictionary.begin(); v!=dictionary.end(); v++) {
  //                if(*v==str) {
  //                    ans = 1;
  //                    break;
  //                }
  //            }
  //
  ////            dout << str << " " << v-dictionary.begin() << " ";
  //            cout << (ans ? "yes" : "no") << endl;
  //        }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric> //accumulate
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
// #define TEST
// //*******************************************************************************************************************************************

//?????????????????¨??§?????\\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
#ifdef TEST
#define dout cout
#else
stringstream dummy; //???????????°??????dout?????????????????????????????????
#define dout                                                                   \\
  dummy.str("");                                                               \\
  dummy.clear(stringstream::goodbit);                                          \\
  dummy // dummy?????????????????????????????????????????¨?????¢?????¢???????????????
//???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§????????????????????????????????????
//http://d.hatena.ne.jp/linden/20060427/p1
#endif

int main(void) {

  int N;
  cin >> N;

  string command;
  string str;

  bool ans;

  vector<string> dictionary;
  vector<string>::iterator v;

  for (int i = 0; i < N; i++) {
    cin >> command >> str;

    if (command[0] == 'i') {
      dictionary.push_back(str); //??????

      v = dictionary.begin();
      while (*v < str)
        v++;

      if (v != dictionary.end()) {
        dictionary.insert(v, str);
        dictionary.pop_back(); //????????????
      }

      //            //display dictionary
      //            for (vector<string>::iterator v=dictionary.begin();
      //            v!=dictionary.end(); v++) dout<<*v<<" "; dout << endl;

    } else if (command[0] == 'f') {
      ans = 0;
      for (v = dictionary.begin(); v != dictionary.end(); v++) {
        if (*v == str) {
          ans = 1;
          break;
        }
      }

      //            dout << str << " " << v-dictionary.begin() << " ";
      cout << (ans ? "yes" : "no") << endl;
    }
  }

  return 0;
}