Stream Compaction
2026/3/9小于 1 分钟
Stream Compaction
题面
对数组 A 进行流压缩:将所有正数(A[i] > 0)按原相对顺序搬移到输出前部,其余位置填 0.0。
Implementation Requirements
- Use only native GPU features (external libraries are not permitted)
- The solve function signature must remain unchanged
- 前 k 位为所有正数(保持稳定次序),k..N-1 置 0.0(A[i]==0 不选)
Examples
A=[1,-2,3,0,-1,4] → out=[1,3,4,0,0,0]Constraints
- 1 ≤ N ≤ 100,000,000;−1000.0 ≤ A[i] ≤ 1000.0
- out 预分配为 N,并初始化为 0.0
- Performance: N = 50,000,000