\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Hackin7} \pdfinfo{ /Title (c-data-structures.pdf) /Creator (Cheatography) /Author (Hackin7) /Subject (C++ Data Structures Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A31A1A} \definecolor{LightBackground}{HTML}{F9F0F0} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{C++ Data Structures Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Hackin7} via \textcolor{DarkBackground}{\uline{cheatography.com/71996/cs/18253/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Hackin7 \\ \uline{cheatography.com/hackin7} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 12th December, 2018.\\ Updated 27th December, 2019.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{2.56 cm} x{5.44 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Pointers}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Storing, data type of pointers and variables must be the same} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \&var & Returns address of memory location of variable \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} data\_type *pointer; & Initialize. Put * in front of name \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} *pointer & Returns value at the memory location stored by pointer \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Array variables are actually pointers to the first element in the array. The amount that your pointer moves from an arithmetic operation} \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} *array & Returns first element in array \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} *(array+2) & Returns third element in array \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{◎ Variables that you declare are stored in a memory location in your \newline computer \newline ◎ The address of these memory locations can be stored in pointers \newline ◎ Addresses are in hexadecimal} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Iterators}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{//Append ::iterator to your data type declaration to create an iterator of \newline that data type \newline vector\textless{}int\textgreater{}::iterator it; // declares an iterator of vector\textless{}int\textgreater{} \newline \newline // loops from the start to end of vi \newline for(vector\textless{}int\textgreater{}::iterator it = vi.begin(); it != vi.end(); it++) \newline cout \textless{}\textless{} {\emph{it \textless{}\textless{} " "; // outputs 1 2 3 4 \newline \newline deque\textless{}int\textgreater{} d; \newline deque\textless{}int\textgreater{}::iterator it; \newline it = d.begin(); //Points to first element \newline it++; // Points to next element \newline it = d.end(); // Points to Last element \newline it-{}-; // Points to previous element \newline cout \textless{}\textless{} }}it; // outputs the element it is pointing} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Iterators are essentially pointers to an STL data structure} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Maps}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{map\textless{}string, int\textgreater{} M; \newline M{[}"hello"{]} = 2; \newline M{[}"asd"{]} = 986; \newline \newline M.count("asd"); // returns 1 \newline M.count("doesnt\_exist"); // returns 0 \newline M.size(); \newline \newline // Check for the existence of some key in the map - O(log N) \newline it = M.find("asd"); //returns the iterator to "asd" \newline it = M.upper\_bound("aaa"); \newline it = M.lower\_bound("aaa"); \newline if (it == M.end()) \newline cout \textless{}\textless{} "Does not exist\textbackslash{}n"; \newline \newline //Iteration \newline for (auto it = mp.begin(); it != mp.end(); ++it) \{ \newline cout \textless{}\textless{} it.first \textless{}\textless{} ", " \textless{}\textless{} it.second \textless{}\textless{} "\textbackslash{}n"; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{A data structure that takes in any data{[}key{]} \newline Gives you the associated value stored through O(log N) magic \newline \newline Best used when you need to lookup certain values in O(log N) time that are associated with other values} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Queue}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{queue\textless{}int\textgreater{} q; \newline \newline q.push(5); // Inserts/ Enqueue element at the back of the queue \newline \newline q.front(); // Returns element atb the front of the queue \newline q.pop // Removes (Dequeues) element from the front of the queue \newline \newline q.empty(); // Returns boolean value of whether queue is empty} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{First In First Out data structure where elements can only be added to the back and accessed at the front} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Priority Queue}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{priority\_queue\textless{}data\_type\textgreater{} pq; // Largest at top \newline priority\_queue\textless{}data\_type, vector\textless{}data\_type\textgreater{}, greater\textless{}data\_type\textgreater{} \textgreater{} \newline pq; // Smallest at top \newline \newline pq.push(5); // pushes element into it. Duplicates are allowed \newline pq.top() // Returns largest or smallest element \newline pq.pop() // Removes largest or smallest element \newline \newline pq.size(); // Returns size \newline pq.empty(); Check if queue is empty} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Like a queue except that only the element with the greatest priority (eg. largest/smallest) can be accessed} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Fenwick tree}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{//Below here can mix \& match \newline long long ft{[}100001{]}; // note: this fenwick tree is 1-indexed. \newline ////PUPQ////////////////////////////////////////////////////// \newline void fenwick\_update(int pos, long long value) \{ \newline while (pos \textless{}= N) \{ \newline //cout\textless{}\textless{}"Fenwick Updating: "\textless{}\textless{}pos\textless{}\textless{}","\textless{}\textless{}value\textless{}\textless{}endl; \newline ft{[}pos{]} += value; \newline \newline pos += pos\&-pos; \newline \} \newline \} \newline long long fenwick\_query(int pos) \{ \newline long long sum = 0; \newline while (pos) \{ // while p \textgreater{} 0 \newline sum += ft{[}pos{]}; \newline pos -= pos\&-pos; \newline \} \newline return sum; \newline \} \newline ////RUPQ////////////////////////////////////////////////////// \newline void \seqsplit{fenwick\_range\_update(int} pos\_a, int pos\_b, int val)\{ \newline //TLE way \newline //for (int i=pos\_a;i\textless{}=pos\_b;i++)\{fenwick\_update(i, val);\} \newline fenwick\_update(pos\_a, val); \newline fenwick\_update(pos\_b+1, -val); \newline \} \newline ////PURQ////////////// \seqsplit{////////////////////////////////////////} \newline long long \seqsplit{fenwick\_range\_query(int} pos\_a, int pos\_b) \{ \newline return fenwick\_query(pos\_b) - \seqsplit{fenwick\_query(pos\_a-1);} \newline \} \newline \newline \newline ////RURQ////////////////////////////////////////////////////// \newline long long B1{[}100001{]};long long B2{[}100001{]}; \newline void base\_update(long long {\emph{ft, int pos, long long value)\{ \newline //Add largest power of 2 dividing x / Last set bit in number x \newline for (; pos \textless{}= N; pos += pos\&(-pos)) \newline ft{[}pos{]} += value; \newline \} \newline void rurq\_range\_update(int a, int b,long long v)\{ \newline base\_update(B1, a, v); \newline base\_update(B1, b + 1, -v); \newline base\_update(B2, a, v }} (a-1)); \newline base\_update(B2, b + 1, -v {\emph{ b); \newline \} \newline void rurq\_point\_update(int a, long long v)\{ \newline rurq\_range\_update(a,a,v); \newline \} \newline long long base\_query(long long }}ft,int b)\{ \newline long long sum = 0; \newline for(; b \textgreater{} 0; b -= b\&(-b)) \newline sum += ft{[}b{]}; \newline return sum; \newline \} \newline // Return sum A{[}1...b{]} \newline long long rurq\_query(int b)\{ \newline return base\_query(B1, b) * b - base\_query(B2, b); \newline \} \newline \newline //Return sum A{[}a...b{]} \newline long long rurq\_range\_query(int a,int b)\{ \newline return rurq\_query(b) - rurq\_query(a-1); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Pair}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{// Initialise \newline pair\textless{}data\_type\_1, data\_type\_2\textgreater{} variable; \newline // OR \newline pair\textless{}data\_type\_1, data\_type\_2\textgreater{} variable = make\_pair(value1,value2); \newline \newline // Store values \newline variable.first = value; \newline variable second = value; \newline // Retrieve values \newline cout \textless{}\textless{}variable first \textless{}\textless{} " " \textless{}\textless{} variable.second \textless{}\textless{} endl; \newline \newline //Nesting pairs \newline pair\textless{}int, pair\textless{}int, int\textgreater{} \textgreater{} a; \newline a.first = 5; \newline a.second.first = 6; \newline a.second.second = 7;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Stores a pair of values} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Stack}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{stack\textless{}int\textgreater{} s; \newline \newline s.push(5); // push an element onto the stack - O(1) \newline s.pop(); // pop an element from the stack - O(1) \newline s.top(); // access the element at the top of the stack - O(1) \newline s.empty(); // whether stack is empty - O(1)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{First-In-Last-Out data structure \newline Only Element at the top can be accessed / removed} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Vector}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{// Initialize \newline vector\textless{}data\_type\textgreater{} v; \newline \newline v.push\_back(value); // Add element to back \newline v.pop\_back() // Remove last element \newline v.clear(); // Remove all elements \newline \newline v{[}index{]} // Return element of index \newline v.back(); // Return last element \newline \newline v.size(); // Return Size of vector \newline v.empty() // Return boolean value of whether vector is empty} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Like arrays but re-sizable. You can add and remove any number of elements from any position.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Sets and Multisets}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{set\textless{}int\textgreater{} s; set\textless{}int\textgreater{}::iterator it; \newline multiset\textless{}int\textgreater{} s; multiset\textless{}int\textgreater{}::iterator it; \newline \newline s.insert(10); \newline \newline it = s.find(8) \newline it = s.upper\_bound(7); \newline it = s.lower\_bound(7); \newline \newline s.erase(10); //Remove element from set \newline s.erase(it) //Can also use iterators \newline \newline s.empty(); \newline s.clear(); \newline \newline // to loop through a set \newline for(it = s.begin(); it != s.end(); it++) \newline cout \textless{}\textless{} *it \textless{}\textless{} " "; // outputs 2 7 10} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{In a set: All elements are sorted and no duplicates \newline Multisets can store duplicates though} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Deque}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{deque\textless{}int\textgreater{} d; \newline \newline // access an element / modify an element (0-indexed as well) - O(1) \newline d{[}0{]} = 2; // change deque from \{5, 10\} to \{2, 10\} \newline d{[}0{]}; // returns a value of 2 \newline \newline d.back(); // get back (last) element - O(1) \newline d.front(); // get front (first) element - O(1) \newline d.clear() // Remove all elements \newline \newline d.push\_back(5); // add an element to the back - O(1) \newline d.push\_front(10); // add an element to the front - O(1) \newline \newline d.pop\_back(); // remove the back (last) element - O(1) \newline d.pop\_front(); // remove the front (first) element - O(1) \newline \newline d.size(); //Return size \newline d.empty // Whether queue is empty} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{A stack and queue combined. \newline ...or a vector that and be pushed and popped from the front as well. \newline \newline Deque = Double Ended Queue!} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Segment Tree}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{struct node \{ \newline int start, end, mid, val, lazyadd; \newline node {\emph{left, }}right; \newline \newline node(int \_s, int \_e) \{ \newline //Range of values stored \newline start = \_s; end = \_e; mid = (start+end)/2; \newline //Min value stored \newline val = 0; lazyadd = 0; \newline if (start!=end) \{ \newline left = new node(start,mid); \newline right = new node(mid+1,end); \newline \} \newline \} \newline \newline int value()\{ \newline if (start==end)\{ \newline val += lazyadd;lazyadd = 0;return val; \newline \}else\{ \newline val += lazyadd; \newline // Propagate Lazyadd \newline right-\textgreater{}lazyadd += lazyadd; \newline left-\textgreater{}lazyadd += lazyadd; \newline lazyadd = 0; \newline return val; \newline \} \newline \} \newline \newline void addRange(int lower\_bound, int upper\_bound, int val\_to\_add)\{ \newline if (start == lower\_bound \&\& end == upper\_bound)\{ \newline lazyadd += val\_to\_add; \newline \}else\{ \newline if (lower\_bound \textgreater{} mid)\{ \newline right-\textgreater{}addRange(lower\_bound, upper\_bound, val\_to\_add); \newline \}else if (upper\_bound \textless{}= mid)\{ \newline left-\textgreater{}addRange(lower\_bound, upper\_bound, val\_to\_add); \newline \}else\{ \newline left-\textgreater{}addRange(lower\_bound, mid, val\_to\_add); \newline right-\textgreater{}addRange(mid+1, upper\_bound, val\_to\_add); \newline \} \newline val = min(left-\textgreater{}value(), right-\textgreater{}value()); \newline \} \newline \} \newline \newline // Update position to new\_value // O(log N) \newline void update(int pos, int new\_val) \{ //position x to new value \newline if (start==end) \{ val=new\_val; return; \} \newline if (pos\textgreater{}mid) right-\textgreater{}update(pos, new\_val); \newline if (pos\textless{}=mid) left-\textgreater{}update(pos, new\_val); \newline val = min(left-\textgreater{}val, right-\textgreater{}val); \newline \} \newline \newline // Range Minimum Query // O(log N) \newline int rangeMinimumQuery(int lower\_bound, int upper\_bound) \{ \newline //cout\textless{}\textless{}"Node:"\textless{}\textless{}start\textless{}\textless{}" "\textless{}\textless{}end\textless{}\textless{}" "\textless{}\textless{}mid\textless{}\textless{}" "\textless{}\textless{}val\textless{}\textless{}endl; \newline //If Query Range \seqsplit{Corresponds////////////////} \newline if (start==lower\_bound \&\& end==upper\_bound)\{ \newline return value(); \newline \} \newline //Query Right Tree if range only lies there \newline else if (lower\_bound \textgreater{} mid)\{ \newline return right-\textgreater{}rangeMinimumQuery(lower\_bound, upper\_bound); \newline \} \newline //Query Left Tree if range only lies there \newline else if (upper\_bound \textless{}= mid)\{ \newline return left-\textgreater{}rangeMinimumQuery(lower\_bound, upper\_bound); \newline \} \newline //Query both ranges as range spans both trees \newline else\{ \newline return min(left-\textgreater{}rangeMinimumQuery(lower\_bound, mid),right-\textgreater{}rangeMinimumQuery(mid+1, upper\_bound)); \newline \} \newline \seqsplit{//End//////////////////////////////////////////} \newline \} \newline \newline \} *root; \newline \newline void init(int N)\{ \newline root = new node(0, N-1); // creates seg tree of size n \newline \} \newline void update(int P, int V)\{ \newline root-\textgreater{}update(P,V); \newline \} \newline int query(int A, int B)\{ \newline int val = root-\textgreater{}rangeMinimumQuery(A,B); \newline return val; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}