t
Size: a a a
t
L
t
DE
p
const union = arr => {
let flatArr = [].concat(...arr);
return [...new Set(flatArr)]
}
const arr1 = [5, 10, 15];
const arr2 = [15, 88, 1, 5, 7];
const arr3 = [100, 15, 10, 1, 5];
console.log(union([arr1, arr2, arr3])); // should log: [5, 10, 15, 88, 1, 7, 100]
t
p
t
L
t
L
L
L
L
L
function binarySimulation(s, q) {
const a = new Int32Array((s.length >> 5) + 1)
for(let i = 0, k = 0; i < s.length; ) {
let i32 = 0
for(let j = 0; j < 32; j++) {
i32 |= ( s[i++]|0 ) << j
}
a[k++] = i32
}
const r = []
for(const v of q) {
switch(v[0]) {
case "I":
const start = v[1] - 1, end = v[2] - 1
let j = start;
const startFl = Math.min( end, ((start >> 5) + 1) << 5 )
//const mask = ( (1 << (startFl - j)) - 1 ) << (j & 31)
//a[j >> 5] ^= mask
while( j < startFl ) {
const byte = j >> 5
const bit = j & 31
const val = 1 << bit
//if ( !bit )
// break
a[byte] ^= val
j++
}
const endFl = (end >> 5) << 5
/// ~250
if ( j < endFl ) {
for(let i = j >> 5; i < end >> 5; i++)
a[i] ^= -1
j = endFl
}
/*
/// ~115
while( j < endFl ) {
const byte = j >> 5
a[byte] ^= -1
j += 32
}
*/
for(; j <= end; j++) {
const byte = j >> 5
const bit = j & 31
const val = 1 << bit
a[byte] ^= val
}
break
case "Q":
const i = v[1] - 1
const byte = i >> 5
const bit = i & 31
r.push( '' + ( (a[byte] >> bit) & 1) )
}
}
return r
}
t
t
t
t