Open In App

Writing code faster in C++ STL

Last Updated : 20 Jul, 2017
Improve
Improve
Like Article
Like
Save
Share
Report

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;
}


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:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads