Types
Primitive types
Section titled “Primitive types”| algo | Meaning |
|---|---|
int | 32-bit signed integer |
long | 64-bit signed integer |
bool | boolean |
float | double-precision floating point |
char | character |
str | string |
With #!int64, source-level int is emitted as a 64-bit integer in generated C++.
Collection types
Section titled “Collection types”| algo | Meaning |
|---|---|
arr[T] | dynamic array |
[T] | shorthand for arr[T] |
[[T]] | nested array |
matrix[T] | two-dimensional array alias |
map[K, V] | hash map |
omap[K, V] | ordered map |
set[T] | hash set |
oset[T] | ordered set |
multiset[T] | ordered multiset |
pq[T] | priority queue |
pq[T, min] | min-priority queue |
stack[T] | stack |
queue[T] | queue |
deque[T] | deque |
pair[A, B] | pair |
Tuple types
Section titled “Tuple types”(int, int)(int, int, int)Use tuple types in return annotations and anywhere a tuple-typed value is expected.
Constructors and filled arrays
Section titled “Constructors and filled arrays”a: [int](n)dp: matrix[int](n)dist = filled(n, INF)grid = filled(n, filled(m, 0))Type aliases
Section titled “Type aliases”type Edge = pair[int, int]type AdjList = [[Edge]]Use aliases when a repeated type is hurting readability.
Generic functions
Section titled “Generic functions”fn <T> identity(x: T) -> T: xInput-block shorthand
Section titled “Input-block shorthand”Inside input: blocks, fixed-size reads can use either style:
input: a: [int][n] b: int[n]Both forms read an array of n integers.