DE
Size: a a a
DE
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
}
L
DE
L
DE
DE
DE
L
L
DE
DE
L
DE
DE
DE
L
function binarySimulation(s, q) {
const array = s.split("").map(Number)
const result = []
const map = {
I(start, end) {
for(let i = start - 1; i < end; i++)
array[i] ^= 1
},
Q(index) {
result.push(array[index - 1] + "")
}
}
for(const [mode, ...args] of q)
map[mode](...args)
return result
}
DE
function binarySimulation(s, q) {
const array = s.split("").map(Number)
const result = []
const map = {
I(start, end) {
for(let i = start - 1; i < end; i++)
array[i] ^= 1
},
Q(index) {
result.push(array[index - 1] + "")
}
}
for(const [mode, ...args] of q)
map[mode](...args)
return result
}
L