Skip to content

Types

algoMeaning
int32-bit signed integer
long64-bit signed integer
boolboolean
floatdouble-precision floating point
charcharacter
strstring

With #!int64, source-level int is emitted as a 64-bit integer in generated C++.

algoMeaning
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
(int, int)
(int, int, int)

Use tuple types in return annotations and anywhere a tuple-typed value is expected.

p = pair[int, int](3, 7)
println p.first # 3
println p.second # 7

For tuples with more than two elements, use get(t, i) to access by compile-time index.

Use void as a return type for functions that do not return a value:

fn clear_all(&a: [int]) -> void:
fill(a, 0)
a: [int](n)
dp: matrix[int](n)
dist = filled(n, INF)
grid = filled(n, filled(m, 0))
type Edge = pair[int, int]
type AdjList = [[Edge]]

Use aliases when a repeated type is hurting readability.

fn <T> identity(x: T) -> T:
x

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.