# Writing code faster in C++ STL

You are wondering some time coder write his code in 2 min or less how? No kidding! Although this tip may not be very useful for competitions such as ICPC or IOI. But there are recent ICPCs ranks where rank i and rank i + 1 are just separated by few minutes. When you can solve the same number of problems as your competitor, it is now down to coding skill and … typing speed.

Try this typing test at typingtest.com and follow the instructions there on how to improve your typing skill.

Many of them uses typedefs, shortcuts, or macros that are commonly used by competitive programmers to speed up the coding time. In this short section, we list down several examples as below.

`// C++ STL shortcuts for ` `// typing codes fast ` `#include <bits/stdc++.h> ` ` ` `// Shortcuts for "common" data types in contests ` `typedef` `long` `long` `ll; ` `typedef` `vector<` `int` `> vi; ` `typedef` `pair<` `int` `, ` `int` `> ii; ` `typedef` `vector<ii> vii; ` `typedef` `set<` `int` `> si; ` `typedef` `map<string, ` `int` `> msi; ` ` ` `// To simplify repetitions/loops, Note: define your ` `// loop style and stick with it! ` `#define REP(i, a, b) \ ` `for` `(` `int` `i = ` `int` `(a); i <= ` `int` `(b); i++) ` `// a to b, and variable i is local! ` `#define TRvi(c, it) \ ` `for` `(vi::iterator it = (c).begin(); it != (c).end(); it++) ` `#define TRvii(c, it) \ ` `for` `(vii::iterator it = (c).begin(); it != (c).end(); it++) ` `#define TRmsi(c, it) \ ` `for` `(msi::iterator it = (c).begin(); it != (c).end(); it++) ` ` ` `#define INF 2000000000 // 2 billion ` ` ` `// If you need to recall how to use memset: ` `#define MEMSET_INF 127 // about 2B ` `#define MEMSET_HALF_INF 63 // about 1B ` ` ` `// memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances ` `// memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table ` `// memset(arr, 0, sizeof arr); // useful to clear array of integers ` ` ` `int` `main() ` `{ ` ` ` `ios_base::sync_with_stdio(` `false` `); ` ` ` `cin.tie(NULL); ` ` ` ` ` `// YOUR CODE GOES HERE ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

Here, typedef and #define are used to short the code and you can use as per your need in main method ios_base::sync_with_stdio(false); and cin.tie(NULL); use for fast io which is reduce the time of running code.

**Related Articles:**

- Writing C/C++ code efficiently in Competitive programming
- How to begin with Competitive Programming?
- Tips and Tricks for Competitive Programmers | Set 1 (For Beginners)

This article is contributed by **Dhavalkumar Prajapati**. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

## Recommended Posts:

- getchar_unlocked() - faster input in C/C++ for Competitive Programming
- Writing C/C++ code efficiently in Competitive programming
- C++: Methods of code shortening in competitive programming
- Speed up Code executions with help of Pragma in C/C++
- Writing code faster during Competitive Programming in C++
- Reverse a subarray of the given array to minimize the sum of elements at even position
- Count of numbers upto N digits formed using digits 0 to K-1 without any adjacent 0s
- Count of square free divisors of a given number
- Minimum cost of reducing Array by merging any adjacent elements repetitively
- Largest number M less than N such that XOR of M and N is even
- Minimize operations required to make each element of Array equal to it's index value
- K-th term from given N merged Arithmetic Progressions
- Count all indices of cyclic regular parenthesis
- Count of all values of N in [L, R] such that count of primes upto N is also prime