cswork / OA打开练习工作台

Capital OneOA #5

Memory Allocator — Aligned Alloc + Erase

估计中等可在线判题

考点(AI 标注)模拟/实现迭代器设计

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.

输入格式

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 one line per request: an allocation returns its starting index or -1; a free returns the number of freed units or -1.

样例 1

输入:

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

输出:

0 16 9 0 8 -1

样例 2

输入:

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

输出:

0 8 1 0

样例 3

输入:

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

输出:

-1 -1 -1