i_anku's blog

By i_anku, history, 2 years ago, In English

map is faster in cpp than unordered_map?

So today I was up solving Codeforces Round #790 (Div. 4) i got stuck in problem F bc i was using unordered_map and repetedly getting tle at 19th and 20th testcase i gave up and tried to look into solution i found out they were using map i tried it and it gets accepted instantaneously, then i wonder which map is faster, tried to look into some online resources but found oppsosite of it every online resource was say unordered_map is faster than map here is my submissions with map unordered_map someone plz help me in this i am really confused, i might get downvote for this but i just want to know the reason thank u

Full text and comments »

  • Vote: I like it
  • +14
  • Vote: I do not like it

By i_anku, history, 3 years ago, In English

USE # TO MAKE SURE PREPROCESSOR DIRECTIVES ARE PRESENT ALSO REFER THE IMAGE ATTACHED LINK: /predownloaded/a4/5d/a45dca13af722302fb8e0c3d6064392213c999c4.jpg hi Everyone Here is a template i managed to get from some famous people

copy the code below: ok lets start with shortcut. vl = vector vll = vector<vector> vc = vector; vs = vector how to use? lets declare a vector long long: vll arr; similarly vs arr1; vc arr2;

some other shortcuts: for loop shortcut +ve for loop fp(i,start,end){ // some code; } i = variable to use; start = starting point; end = ending point + 1;

-ve for loop: fn(i,start,end){ // some code; } i : variable start : start point; end : end point -1;

for debuging ure code: make a document name as "error.txt"

lets have a variable: int a = 10 int b = 19; vl arr = {1,2,3,4,6}; vc arr1 = {'a','b','c'}; //lets debug

debug(a); debug(b); debug(arr); debug(arr1);

//expected output on error.txt // a 10 // b 19 // arr [ 1 2 3 4 5 6 ] // arr1 [ a b c ]

include<bits/stdc++.h>

using namespace std;

typedef long long ll; typedef unsigned long long ull; typedef long double lld;

define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

define MOD 1000000007

define MOD1 998244353

define INF 1e18

define nline "\n"

define pb push_back

define ppb pop_back

define mp make_pair

define ff first

define ss second

define PI 3.141592653589793238462

define set_bits __builtin_popcountll

define sz(x) ((int)(x).size())

define all(x) (x).begin(), (x).end()

define fp(i,start,end) for(ll i = start;i < end; i++)

define fn(i,start,end) for(ll i = start;i > end; i--)

define vl vector

define vc vector

define vs vector

define vll vector<vector>

// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key

ifndef ONLINE_JUDGE

define debug(x) cerr << #x <<" "; _print(x); cerr << endl;

else

define debug(x)

endif

void _print(ll t) {cerr << t;} void _print(int t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(lld t) {cerr << t;} void _print(double t) {cerr << t;} void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p); template void _print(vector v); template void _print(set v); template <class T, class V> void _print(map <T, V> v); template void _print(multiset v); template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

void solve(){

}

int main() { fastio();

ifndef ONLINE_JUDGE

freopen("Error.txt", "w", stderr);
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);

endif

solve()

}

//comment if u have any trouble understanding the code

Full text and comments »

  • Vote: I like it
  • -49
  • Vote: I do not like it