Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

which one is faster map or unordered_map in cpp? [confused]
Разница между en1 и en2, 2 символ(ов) изменены
I was trying to the [this](https://cses.fi/problemset/task/1640/) question and during that, I used the following code. ↵

~~~~~↵
void solve() {↵

    read(n); read(x);↵
    map<int,int>mp;↵
    for(int i = 0; i< n; i++){↵
        int a; cin>>a;↵
        if(mp.find(a) != mp.end()){↵
            int b = mp[a]+1;↵
            cout<<b<<" "<<i+1<<endl;↵
            return;↵
        }↵
        else{↵
            mp[x-a] = i;↵
        }↵
    }↵
    cout<<"IMPOSSIBLE"<<endl;↵


}↵
~~~~~↵
this did not give any tle error but when i used the following code ↵


~~~~~↵
void solve() {↵

    read(n); read(x);↵
    unordered_map<int,int>mp;↵
    for(int i = 0; i< n; i++){↵
        int a; cin>>a;↵
        if(mp.find(a) != mp.end()){↵
            int b = mp[a]+1;↵
            cout<<b<<" "<<i+1<<endl;↵
            return;↵
        }↵
        else{↵
            mp[x-a] = i;↵
        }↵
    }↵
    cout<<"IMPOSSIBLE"<<endl;↵


}↵
~~~~~↵
it was giving tle in the test cases 23 and 24. now I know that both of them are the same except for the use of data structure, but the map should be slower than unordered_map but the opposite is true, why is this happening can anyone explain?↵

[code of unordered_map](https://cses.fi/paste/93e2e3b621eed69579e8b4/)↵

[code for map](https://cses.fi/paste/817dd306bdee85e279e8c5/)↵

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский ErenZ 2023-12-21 19:03:47 2 Tiny change: 'g code. \n~~~~~\nv' -> 'g code. \n\n~~~~~\nv'
en1 Английский ErenZ 2023-12-21 19:03:06 1378 Initial revision (published)