cswork / OAOpen practice workspace

Capital OneOA #5

Memory Allocator — Aligned Alloc + Erase

Estimated MediumJudge-ready

Topics (AI-labelled)SimulationIterators

Allocate the leftmost contiguous free block that starts at a boundary of 8 units; later, an entire block can be freed by its allocation ID.

Input

n q; a line with n initial states of 0/1; then q lines: 0 x requests x units, and 1 id frees id. Indices start at 0; initially occupied units do not belong to any freeable allocation. Site supplement: n≤5000, q≤1000, x≥1.

Output

Output one line per request: an allocation returns its starting index or -1; a free returns the number of freed units or -1.

Example 1

Input:

24 6
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 9
0 8
1 1
0 8
1 2
1 99

Output:

0 16 9 0 8 -1

Example 2

Input:

16 4
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1
0 1
1 1
0 8

Output:

0 8 1 0

Example 3

Input:

8 3
1 0 0 0 0 0 0 0
0 1
1 1
0 8

Output:

-1 -1 -1

Editorial

Loading solution…