My code got accepted when I use map<> but, I got tle when I use unordered_map<>.why ??
Difference between en1 and en2, changed 1,581 character(s)
AlthoughHere I'm doing only searching work and for searching only.unordered_map<> takes O(1) timefor searching and map<>takes O(long) time ↵
Here is my tle code :)↵

#include<bits/stdc++.h>↵
using namespace std;↵
#define ll long long int ↵
#define nl "\n"↵
#define pb push_back↵
#define ppb pop_back↵
#define umap unordered_map↵
#define uset unordered_set↵
#define lb lower_bound↵
#define ub upper_bound↵
#define mod1 1000000007↵
#define v vector<ll>↵
#define tt int TESTCASE;cin>>TESTCASE;while(TESTCASE--)↵
#define f(i,a,b) for(ll i = (a); i <= (b); i++)↵
#define fr(i,a,b) for(ll i = (a); i >= (b); i--)↵

void print(v &vect,ll len){↵
  f(i,0,len-1)cout<<vect[i]<<" ";↵
  cout<<nl;↵
}↵

ll power(ll a,ll b){ //Finding a power b..↵
 ll ans=1;↵
  while(b){↵
    ↵
     if(b&1){↵
        ans=a*ans;↵
     }↵
     b>>=1;↵
     a=a*a;↵
  }↵
  return ans;↵
}↵
ll find_gcd(ll a,ll b){ //Taking b as divisor and a as dividend↵
  if( b==0 ) return a;  ↵
  return find_gcd( b , a%b ); ↵
}↵

/*------------------------------------- IT'S MY WORLD :)) -----------------------------------------*/↵
int main() {↵
 ios_base::sync_with_stdio(false);↵
 cout.tie(NULL); cin.tie(NULL);↵
tt{↵
    ll n,x;cin>>n>>x;umap<ll,ll>mp;↵
    v vect(n);f(i,0,n-1){↵
      cin>>vect[i];↵
      mp[vect[i]]++;↵
    }↵
    sort(vect.begin(),vect.end());ll cnt=0;↵
    f(i,0,n-1){↵
      ll temp=vect[i];↵
      if(mp.find(temp)!=mp.end()){↵
        if(mp[temp]!=0){↵
         ll xxx=temp*x;↵
          if(mp.find(xxx)!=mp.end() && mp[xxx]!=0){↵
            mp[temp]--;mp[xxx]--;↵
          }↵
          else {↵
            cnt++;mp[temp]--;↵
          }↵
        }↵
        ↵
      }↵
    }↵
    cout<<cnt<<nl;↵
 ↵
}↵
return 0;↵
}
for searching so I didn't get that why I'm getting tle.↵
Here is my code link -:↵

https://codeforces.com/contest/1642/submission/147498144↵
 ↵
Above is my tle code.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English rinku11 2022-02-24 10:50:30 1581
en1 English rinku11 2022-02-24 10:43:31 1771 Initial revision (published)