Could anybody help me find out how this could code run for more than 2 second ? Where 1 ≤ N ≤ 10^6 and 1 ≤ Q ≤ 2⋅10^5. Since push_back function to a vector have time complexity of O(1) and accessing from an unordered_map has also time complexity of O(1).
#include<iostream>
#include<unordered_map>
#include<vector>
using namespace std;
bool check[1000000];
int main() {
int N, Q, n;
bool c = false;
int last_reset[2] = {0,0};
string Y;
cin >> N >> Q;
unordered_map<int,pair<int,int>> J;
vector<int> H;
for (short i = 0; i < Q; i++)
{
cin >> Y >> n;
if(Y=="SET") m = 1;
else if(Y=="RESTART") m = 2;
else m = 3;
switch (m)
{
case 1:
cin >> u;
check[n-1] = true;
J[n] = {u,i+1};
break;
case 2:
c = true;
last_reset[0] = n;
last_reset[1] = i+1;
break;
case 3:
if (c && check[n-1] && last_reset[1] > J[n].second)
H.push_back(last_reset[0]);
else if (c && check[n-1] && last_reset[1] < J[n].second)
H.push_back(J[n].first);
else if(check[n-1] && !c)
H.push_back(J[n].first);
else if(!check[n-1] && c)
H.push_back(last_reset[0]);
else
H.push_back(0);
break;
default:
break;
}
}
for (auto i:H)
cout << i << endl;
return 0;
}