Storing boolean array-like object of size 1e9 in Python3

Revision en2, by PiStroke, 2022-06-19 09:39:16

Recently, I came across this blog which explains bitwise operations in vector <bool> (c++).

Problem: You are given 10**7 integers in the range [0,10**9], find the number of distinct integers.

In python making a boolean list/array wouldn't help, an integer will occupy at least 24 bits and a bool will occupy 8 bits, the issue is it would lead to MLE, which isn't desirable!

Are there any python alternatives for vector <bool>?

I looked up numPy (even though it's not allowed in online Judge) but it doesn't seem to have one. Bitarray might be of some help, but I believe it's not allowed in Online Judge either.

Tags python3, bitarray, bool, memory limit

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English PiStroke 2022-06-19 09:39:16 12 Tiny change: 'for vector<bool>?\n\nI lo' -> 'for vector/<bool/>?\n\nI lo'
en1 English PiStroke 2022-06-19 09:35:59 720 Initial revision (published)