# OROFAND | April Cook Off

Apr 19th, 2021 (edited)
390
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def incrementBitMap(bitMap, num):
2.     bit = f"{num:031b}"
3.     for i in range(1, 32):
4.         bitMap[i] += int(bit[i-1])
5.
6. def decrementBitMap(bitMap, num):
7.     bit = f"{num:031b}"
8.     for i in range(1, 32):
9.         bitMap[i] -= int(bit[i-1])
10.
11. def finalScore(bitMap):
12.     bin = ""
13.     for i in range(1, 32):
14.         digit = 1 if bitMap[i] > 0 else 0
15.         bin = f"{bin}{digit}"
16.     return int(bin, 2)
17.
18. def query(bitMap):
19.     x, v = map(int, input().split())
20.     decrementBitMap(bitMap, arr[x-1])
21.     incrementBitMap(bitMap, v)
22.     arr[x-1] = v
23.     print(finalScore(bitMap))
24.
25. for _ in range(int(input())):
26.     n, q = map(int, input().split())
27.     arr = [int(x) for x in input().split()]
28.     bitMap = {i: 0 for i in range(1, 32)}
29.
30.     for a in arr:
31.         incrementBitMap(bitMap, a)
32.
33.     print(finalScore(bitMap))
34.
35.     for _ in range(q):
36.         query(bitMap)
37.
RAW Paste Data