description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: mask = 0 mp = {"a": 0, "e": 1, "i": 2, "o": 3, "u": 4} seen = [len(s)] * 63 seen[0] = -1 max_len = 0 for i in range(len(s)): if s[i] in "aeiou": mask ^= 1 << mp[s[i]] seen[mask] = min(seen[mask], i) max_len = max(max_len, i - seen[mask]) return max_len
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: for i in range(len(s), 0, -1): for j in range(len(s) - i + 1): sub = s[j : j + i] has_odd_vowel = False for vowel in ["a", "e", "i", "o", "u"]: if sub.count(vowel) % 2 != 0: has_odd_vowel = True break if not has_odd_vowel: return i return 0
CLASS_DEF FUNC_DEF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR LIST STRING STRING STRING STRING STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR RETURN VAR RETURN NUMBER VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: bits = {"a": 1, "e": 2, "i": 3, "o": 4, "u": 5} dp = {(0): -1} ans, state = 0, 0 for i, c in enumerate(s): if c in bits: state ^= 1 << bits[c] ans = max(ans, i - dp.get(state, 128)) dp[state] = min(dp.get(state, 128), i) return ans
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: res = 0 pos = {(0): -1} state = 0 vowels = "aeiou" for i in range(len(s)): j = vowels.find(s[i]) if j >= 0: state ^= 1 << j if state in pos: res = max(res, i - pos[state]) else: pos[state] = i return res
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: max_substring_size = 0 processed_cons = None s_len = len(s) for i in range(s_len): if processed_cons == True: if ( s[i] == "a" or s[i] == "e" or s[i] == "i" or s[i] == "o" or s[i] == "u" ): processed_cons = False continue if s[i] == "a" or s[i] == "e" or s[i] == "i" or s[i] == "o" or s[i] == "u": processed_cons = False else: processed_cons = True if max_substring_size > s_len - i: break vowel_counts = {"a": 0, "e": 0, "i": 0, "o": 0, "u": 0} allEven = True for k, letter in enumerate(s[i:]): if letter in vowel_counts: vowel_counts[letter] += 1 currently_all_even = True for count in list(vowel_counts.values()): if count % 2 == 1: currently_all_even = False break allEven = currently_all_even if allEven and k + 1 > max_substring_size: max_substring_size = k + 1 return max_substring_size
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: substrings = self.generate_subst(s) res = 0 for substring in substrings: is_all_even = True for ch in "aeiou": if substring.count(ch) % 2: is_all_even = False break if is_all_even: return len(substring) return res def generate_subst(self, s: str): for window_size in range(len(s), -1, -1): for i in range(len(s) - window_size + 1): yield s[i : i + window_size]
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR RETURN FUNC_CALL VAR VAR RETURN VAR VAR FUNC_DEF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR VAR VAR BIN_OP VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: mask, seen, smax, vowels = ( 0, {(0): -1}, 0, {x: (1 << i) for i, x in enumerate("aeiou")}, ) for i, x in enumerate(s): if x in vowels: mask ^= 1 << vowels[x] seen.setdefault(mask, i) smax = max(smax, i - seen[mask]) return smax
CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR VAR VAR NUMBER DICT NUMBER NUMBER NUMBER VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring1(self, s: str) -> int: def check(L, R, cnt_memo): if L > R: return 0 elif (L, R) in memo: return memo[L, R] elif all(v % 2 == 0 for v in list(cnt_memo.values())): return R - L + 1 else: old_L = L new_memo = {k: v for k, v in list(cnt_memo.items())} while s[L] not in "aeiou": L += 1 new_memo[s[L]] -= 1 if new_memo[s[L]] == 0: del new_memo[s[L]] res1 = check(L + 1, R, new_memo) L = old_L old_R = R new_memo = {k: v for k, v in list(cnt_memo.items())} while s[R] not in "aeiou": R -= 1 new_memo[s[R]] -= 1 if new_memo[s[R]] == 0: del new_memo[s[R]] res2 = check(L, R - 1, new_memo) R = old_R res = max(res1, res2) memo[L, R] = res return res cnt_memo = collections.Counter(s) cnt_memo = {k: v for k, v in list(cnt_memo.items()) if k in "aeiou"} memo = dict() res = check(0, len(s) - 1, cnt_memo) return res def findTheLongestSubstring(self, s: str) -> int: res = 0 curr = 0 memo = dict() memo[0] = -1 for i, c in enumerate(s): if c == "a": curr ^= 1 elif c == "e": curr ^= 2 elif c == "i": curr ^= 4 elif c == "o": curr ^= 8 elif c == "u": curr ^= 16 if curr in memo: res = max(res, i - memo[curr]) else: memo[curr] = i return res return
CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR STRING VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR STRING VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN VAR VAR FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR RETURN VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: vowels_bit_mask = {v: (2**i) for i, v in enumerate("aeiou")} vowel_state = 0 first_index_of_recorded_state = {(0): -1} max_substr_len = 0 for index, char in enumerate(s): if char in vowels_bit_mask: vowel_state ^= vowels_bit_mask[char] if vowel_state in first_index_of_recorded_state: max_substr_len = max( max_substr_len, index - first_index_of_recorded_state[vowel_state] ) else: first_index_of_recorded_state[vowel_state] = index return max_substr_len
CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: bits = {"a": 1, "e": 2, "i": 4, "o": 8, "u": 16} seen = {(0): -1} max_val = 0 cur = 0 for i, char in enumerate(s): if char in bits: cur ^= bits[char] seen.setdefault(cur, i) max_val = max(max_val, i - seen[cur]) return max_val
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: states = [(False, False, False, False, False)] seen = {} mapping = {"a": 0, "e": 1, "i": 2, "o": 3, "u": 4} for i in range(len(s)): vector = list(states[-1]) character = s[i] if character in mapping: vector[mapping[character]] = not vector[mapping[character]] states.append(tuple(vector)) res = 0 for i, v in enumerate(states): if v in seen: res = max(res, i - seen[v]) else: seen[v] = i return res
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: vowels = set("aeiou") odd = {tuple(): -1} key = tuple() res = 0 window = collections.Counter() vowel_count = [window] for i, char in enumerate(s): if char in vowels: window[char] += 1 key = tuple(c for c in window if window[c] & 1) if key in odd: res = max(i - odd[key], res) else: odd[key] = i else: res = max(i - odd[key], res) else: res = max(i - odd[key], res) return res
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR DICT FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: vowels = {x: (1 << i) for i, x in enumerate("aeiou")} fst = {(0): -1} ans = mask = 0 for i, c in enumerate(s): if c in vowels: mask ^= vowels[c] fst.setdefault(mask, i) ans = max(ans, i - fst[mask]) return ans
CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: left_states = {"": -1} cur_state = set() ans = 0 for i, char in enumerate(s): if char in "aeiou": if char in cur_state: cur_state.remove(char) else: cur_state.add(char) cur_state_str = "".join(sorted(list(cur_state))) if cur_state_str in left_states: ans = max(ans, i - left_states[cur_state_str]) else: left_states[cur_state_str] = i return ans
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT STRING NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: s = s + "a" bits, dp = {"a": 0, "e": 1, "i": 2, "o": 3, "u": 4}, {(0): -1} res = 0 key = 0 for i, char in enumerate(s): if char in bits: if key in dp: res = max(res, i - dp[key] - 1) key = key ^ 1 << bits[char] if key not in dp: dp[key] = i return res
CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: P = [0] vowels = "aeiou" for c in s: i = vowels.find(c) mask = 1 << i if i != -1 else 0 P.append(P[-1] ^ mask) ans = 0 fst = {} for i, p in enumerate(P): if p in fst: h = fst[p] ans = max(ans, i - h) fst.setdefault(p, i) return ans
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST NUMBER ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: first_position = {(0, 0, 0, 0, 0): -1} counter = {"a": 0, "e": 0, "i": 0, "o": 0, "u": 0} ans = 0 for i, c in enumerate(s): if c in counter: counter[c] += 1 key = tuple([(counter[c] % 2) for c in "aeiou"]) if key not in first_position: first_position[key] = i ans = max(i - first_position[key], ans) return ans
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR STRING IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: masks = {(0): -1} mask = 0 match = {"a": 1, "e": 2, "i": 4, "o": 8, "u": 16} max_len = 0 for i, ch in enumerate(s): if ch in match: mask = mask ^ 1 << match[ch] if mask in masks: max_len = max(max_len, i - masks[mask]) else: masks[mask] = i return max_len
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: lu = {"a": 0, "e": 1, "i": 2, "o": 3, "u": 4} def setFlags(flags: int, ch: str) -> int: if ch in lu.keys(): mask = 1 << lu[ch] flags = flags ^ mask return flags FLAGS = 0 seen = {(0): -1} m = 0 for i, c in enumerate(s): FLAGS = setFlags(FLAGS, c) if FLAGS in seen.keys(): m = max(m, i - seen[FLAGS]) else: seen[FLAGS] = i return m
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: state = 0 d = {(0): -1} vowels = {"a": 1, "e": 2, "i": 4, "o": 8, "u": 16} max_len = 0 for i in range(len(s)): if s[i] in vowels: state ^= vowels[s[i]] if state not in d: d[state] = i if state in d: max_len = max(max_len, i - d[state]) return max_len
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: cur = 0 res = 0 seen = {} seen[0] = -1 for i, c in enumerate(s): cur ^= 1 << "aeiou".find(c) + 1 >> 1 if cur not in seen: seen[cur] = i res = max(res, i - seen[cur]) return res
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL STRING VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: memo = {(0): 0} dic = dict(list(zip("aeiou", list(range(5))))) curr, ans = 0, 0 for k, v in enumerate(s, 1): if v in dic: curr ^= 1 << dic[v] if curr in memo: ans = max(ans, k - memo[curr]) else: memo[curr] = k return ans
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: vowel_dict = {"a": 0, "e": 1, "i": 2, "o": 3, "u": 4} integrals = [(False, False, False, False, False)] for l in s: vector = list(integrals[-1]) if l in vowel_dict: vector[vowel_dict[l]] = not vector[vowel_dict[l]] integrals.append(tuple(vector)) seen = {} res = 0 for i, v in enumerate(integrals): if v in seen: res = max(res, i - seen[v]) else: seen[v] = i return res
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: bin_map = collections.defaultdict(int) for i, c in enumerate(["a", "e", "i", "o", "u"]): bin_map[c] = 1 << i cur_bin = 0 prev_bin = {(0): -1} ans = 0 for index, c in enumerate(s): cur_bin ^= bin_map[c] if cur_bin in prev_bin: ans = max(ans, index - prev_bin[cur_bin]) else: prev_bin[cur_bin] = index return ans
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
VOWELS = {"a": 1, "e": 2, "i": 4, "o": 8, "u": 16} class Solution: def findTheLongestSubstring(self, s: str) -> int: seen = {(0): -1} mask = 0 longest = 0 for ind, char in enumerate(s): mask ^= VOWELS.get(char, 0) if mask not in seen: seen[mask] = ind else: longest = max(longest, ind - seen[mask]) return longest
ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: dp = [-1] + [len(s)] * 31 mask = 0 res = 0 for i, c in enumerate(s): if c in "aeiou": mask ^= 1 << "aeiou".index(c) dp[mask] = min(dp[mask], i) res = max(res, i - dp[mask]) return res
CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP NUMBER FUNC_CALL STRING VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: n = len(s) dp = {} for k in range(n, 0, -1): for i in range(0, n + 1 - k): if k == n: s_count = collections.Counter(s) dp[i, k] = [(s_count.get(c, 0) % 2 == 0) for c in "aeiou"] elif i == 0: dp[i, k] = self.update_tracker(s[i + k], dp.get((i, k + 1))) else: dp[i, k] = self.update_tracker(s[i - 1], dp.get((i - 1, k + 1))) if all(dp[i, k]): return k return 0 def update_tracker(self, char, tracker): idx = "aeiou".find(char) new_tracker = list(tracker) if idx > -1: new_tracker[idx] = not tracker[idx] return new_tracker
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR STRING IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN VAR RETURN NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Example 1: Input: s = "eleetminicoworoep" Output: 13 Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u. Example 2: Input: s = "leetcodeisgreat" Output: 5 Explanation: The longest substring is "leetc" which contains two e's. Example 3: Input: s = "bcbcbc" Output: 6 Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.   Constraints: 1 <= s.length <= 5 x 10^5 s contains only lowercase English letters.
class Solution: def findTheLongestSubstring(self, s: str) -> int: def countVowels(ct): if ( not ct["a"] % 2 and not ct["e"] % 2 and not ct["i"] % 2 and not ct["o"] % 2 and not ct["u"] % 2 ): return True return False for i in range(len(s)): ctr = collections.Counter(s[: len(s) - i]) for j in range(i + 1): if j != 0: ctr[s[j - 1]] -= 1 ctr[s[len(s) + j - i - 1]] += 1 if countVowels(ctr): return sum(ctr.values()) return 0
CLASS_DEF FUNC_DEF VAR FUNC_DEF IF BIN_OP VAR STRING NUMBER BIN_OP VAR STRING NUMBER BIN_OP VAR STRING NUMBER BIN_OP VAR STRING NUMBER BIN_OP VAR STRING NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR RETURN NUMBER VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: lx = [arr[0]] for i in range(1, len(arr)): lx.append(lx[i - 1] ^ arr[i]) return [(lx[i[1]] if i[0] == 0 else lx[i[0] - 1] ^ lx[i[1]]) for i in queries]
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: ans = [] a = [arr[0]] for i in range(1, len(arr)): a.append(arr[i] ^ a[i - 1]) for q in queries: if q[0] == 0: ans.append(a[q[1]]) else: ans.append(a[q[1]] ^ a[q[0] - 1]) return ans
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: res = [] n = len(arr) tmp = [arr[0]] for i in range(1, n): tmp.append(tmp[-1] ^ arr[i]) for x, y in queries: if x == 0: res.append(tmp[y]) else: res.append(tmp[x - 1] ^ tmp[y]) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: xors = [0] for a in arr: xors.append(xors[-1] ^ a) res = [] for i, j in queries: res.append(xors[j + 1] ^ xors[i]) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: acc = [0] for i in range(len(arr)): acc.append(acc[i] ^ arr[i]) result = [] for q in queries: result.append(acc[q[0]] ^ acc[q[1] + 1]) return result
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: for i in range(1, len(arr)): arr[i] ^= arr[i - 1] result = [] for x, y in queries: if x == 0: result.append(arr[y]) else: result.append(arr[y] ^ arr[x - 1]) return result
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: store = {} n = len(arr) curr = 0 store[-1] = 0 for i in range(n): curr ^= arr[i] store[i] = curr return [(store[b] ^ store[a - 1]) for a, b in queries]
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: n = len(arr) ans = [] prefix = [0] * n prefix[0] = arr[0] for i in range(1, n): prefix[i] = prefix[i - 1] ^ arr[i] for q in queries: l, r = q if l == 0: ans.append(prefix[r]) else: ans.append(prefix[r] ^ prefix[l - 1]) return ans
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: if arr == []: return [] res = [] pre = [arr[0]] for i in range(1, len(arr)): pre.append(arr[i] ^ pre[-1]) for i in range(0, len(queries)): xor = 0 if queries[i][0] == queries[i][1]: res.append(arr[queries[i][0]]) elif abs(queries[i][0] - queries[i][1]) == 1: res.append(arr[queries[i][0]] ^ arr[queries[i][1]]) elif queries[i][0] == 0: res.append(pre[queries[i][1]]) else: res.append(pre[queries[i][1]] ^ pre[queries[i][0] - 1]) print(res) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR IF VAR LIST RETURN LIST ASSIGN VAR LIST ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: prefix = [] curr = 0 for n in arr: curr ^= n prefix.append(curr) res = [] for l, r in queries: if l == 0: res.append(prefix[r]) else: res.append(prefix[r] ^ prefix[l - 1]) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: pre_xor = [0] size_arr = len(arr) if size_arr % 2 == 0: for i in range(0, size_arr, 2): pre_xor.append(pre_xor[i] ^ arr[i]) pre_xor.append(pre_xor[i + 1] ^ arr[i + 1]) else: pre_xor.append(pre_xor[0] ^ arr[0]) for i in range(1, size_arr, 2): pre_xor.append(pre_xor[i] ^ arr[i]) pre_xor.append(pre_xor[i + 1] ^ arr[i + 1]) out_xor = [] for L, R in queries: out_xor.append(pre_xor[L] ^ pre_xor[R + 1]) return out_xor
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: if len(arr) == 1: return [arr[0] for i in queries] table = [arr[0]] * len(arr) for i in range(1, len(arr)): table[i] = table[i - 1] ^ arr[i] out = [0] * len(queries) for i, (l, r) in enumerate(queries): if l > 0: out[i] = table[l - 1] ^ table[r] else: out[i] = table[r] return out
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: xors = [] xoraccum = 0 for n in arr: xoraccum ^= n xors.append(xoraccum) ret = [] for query in queries: l, r = query[0], query[1] rxor = xors[r] lxor = 0 if l == 0 else xors[l - 1] ret.append(rxor ^ lxor) return ret
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: x = 0 xors = [] for i in arr: x ^= i xors.append(x) return [(xors[i[1]] ^ xors[i[0]] ^ arr[i[0]]) for i in queries]
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: px = arr[:] for i in range(1, len(px)): px[i] ^= px[i - 1] res = [] for q in queries: s, e = q[0], q[1] r = px[e] if s: r ^= px[s - 1] res.append(r) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: xor_arr = [0] * len(arr) xor_arr[0] = arr[0] for i in range(1, len(arr)): xor_arr[i] = xor_arr[i - 1] ^ arr[i] res = [0] * len(queries) for i, (s, e) in enumerate(queries): if s == e: res[i] = arr[s] elif s == 0: res[i] = xor_arr[e] else: res[i] = xor_arr[e] ^ xor_arr[s - 1] return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: def constSeg(tree, n, arr): tree[n:] = arr for i in range(n - 1, 0, -1): tree[i] = tree[2 * i] ^ tree[2 * i + 1] def getQuery(beg, end): beg += n end += n ans = 0 while beg < end: if beg & 1: ans ^= tree[beg] beg += 1 if end & 1: end -= 1 ans ^= tree[end] beg //= 2 end //= 2 return ans n = len(arr) tree = [0] * (2 * len(arr)) constSeg(tree, len(arr), arr) ans = [] for i in queries: ans.append(getQuery(i[0], i[1] + 1)) return ans
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: arr.insert(0, 0) for i in range(1, len(arr)): arr[i] ^= arr[i - 1] return [(arr[a] ^ arr[b + 1]) for a, b in queries]
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: n = len(arr) out = [] tree = [0] * (2 * n) for i in range(n): tree[i + n] = arr[i] for i in range(n - 1, 0, -1): tree[i] = tree[i << 1] ^ tree[i << 1 | 1] for q in queries: res = 0 l = q[0] + n r = q[1] + n + 1 while l < r: if l & 1: res = res ^ tree[l] l = l + 1 if r & 1: r = r - 1 res = res ^ tree[r] l >>= 1 r >>= 1 out.append(res) return out
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: for i in range(1, len(arr)): arr[i] ^= arr[i - 1] for i, q in enumerate(queries): if q[0] == 0: queries[i] = arr[q[1]] else: queries[i] = arr[q[0] - 1] ^ arr[q[1]] return queries
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: n = len(arr) prefix = [0] * (n + 1) for i in range(n): prefix[i + 1] = prefix[i] ^ arr[i] res = [] for x, y in queries: res.append(prefix[y + 1] ^ prefix[x]) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: cumArr = [] resultArr = [] for index in range(len(arr)): if index == 0: cumArr.insert(index, arr[index]) else: cumArr.insert(index, arr[index] ^ cumArr[index - 1]) for query in queries: left = query[0] right = query[1] if left is not 0: resultArr.append(cumArr[right] ^ cumArr[left - 1]) else: resultArr.append(cumArr[right]) return resultArr
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: prefix = [0] * len(arr) prefix[0] = arr[0] for i in range(1, len(arr)): prefix[i] = prefix[i - 1] ^ arr[i] ans = [] for query in queries: start = query[0] end = query[1] if start == 0: ans.append(prefix[end]) else: ans.append(prefix[start - 1] ^ prefix[end]) return ans
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: b = [arr[0]] for a in arr[1:]: b.append(b[-1] ^ a) ans = [] for q in queries: r = b[q[1]] if q[0] > 0: r ^= b[q[0] - 1] ans.append(r) return ans
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: n = len(arr) precompute = [] xor = 0 for num in arr: xor ^= num precompute.append(xor) ans = [] for s, e in queries: if s == 0: ans += [precompute[e]] else: ans += [precompute[e] ^ precompute[s - 1]] return ans
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR IF VAR NUMBER VAR LIST VAR VAR VAR LIST BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: tree = [] n = 0 def SegmentTree(self, arr): nonlocal tree, n n = len(arr) tree = [0] * 2 * n for i in range(n): tree[i + n] = arr[i] for j in range(n - 1, 0, -1): tree[j] = tree[2 * j] ^ tree[2 * j + 1] def xor(self, frm, to): nonlocal tree, n frm += n to += n value = 0 while frm < to: if frm & 1 == 1: value ^= tree[frm] frm += 1 if to & 1 == 1: to -= 1 value ^= tree[to] frm >>= 1 to >>= 1 return value def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: self.SegmentTree(arr) result = [] for query in queries: result.append(self.xor(query[0], query[1] + 1)) return result
CLASS_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: prefixSum = [0] * len(arr) prefixSum[0] = arr[0] result = [] for i in range(1, len(arr)): prefixSum[i] = prefixSum[i - 1] ^ arr[i] for i in queries: if i[0] == 0: result.append(prefixSum[i[1]]) continue result.append(prefixSum[i[1]] ^ prefixSum[i[0] - 1]) return result
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: xored = [None] * len(arr) ans = [None] * len(queries) xored[0] = arr[0] for i in range(1, len(arr)): xored[i] = xored[i - 1] ^ arr[i] for i in range(len(queries)): L = queries[i][0] R = queries[i][1] if L > 0: ans[i] = xored[L - 1] ^ xored[R] else: ans[i] = xored[R] return ans
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, A: List[int], queries: List[List[int]]) -> List[int]: for i in range(len(A) - 1): A[i + 1] ^= A[i] return [(A[j] ^ A[i - 1] if i else A[j]) for i, j in queries]
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: xors = [arr[0]] n = len(arr) for i in range(1, n): xors.append(xors[-1] ^ arr[i]) res = [] for query in queries: l, r = query temp = xors[r] if l != 0: temp ^= xors[l - 1] res.append(temp) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: n = len(arr) m = len(queries) d = {} res = [] d["0 0"] = arr[0] for i in range(1, n): key = "{} {}".format(0, i) pkey = "{} {}".format(0, i - 1) d[key] = d[pkey] ^ arr[i] print(d) for i in range(0, m): u, v = queries[i] s = 0 key2 = "{u} {v}".format(u=u, v=v) if key2 in d: res.append(d[key2]) continue pkey = "{} {}".format(0, u - 1) key = "{} {}".format(0, v) s = d[pkey] ^ d[key] print(d[pkey], d[key], s) res.append(s) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL STRING NUMBER VAR ASSIGN VAR FUNC_CALL STRING NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: n = len(arr) prefix = [(0) for _ in range(n + 1)] for i in range(n): prefix[i + 1] = prefix[i] ^ arr[i] res = [] print(prefix) for l, r in queries: print((l, r)) res.append(prefix[r + 1] ^ prefix[l]) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: a = arr q = queries l = [] for i in range(len(a) - 1): a[i + 1] ^= a[i] print(a) for i, j in q: if i: l.append(a[j] ^ a[i - 1]) else: l.append(a[j]) return l
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: ans = [] for i in range(1, len(arr)): arr[i] ^= arr[i - 1] return [(arr[j] ^ arr[i - 1] if i > 0 else arr[j]) for i, j in queries]
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: if len(arr) == 0: return [] xor_arr = [(0) for i in range(len(arr))] for index, v in enumerate(arr): if index == 0: xor_arr[index] = arr[index] else: xor_arr[index] = xor_arr[index - 1] ^ arr[index] results = [(0) for i in range(len(queries))] for index, query in enumerate(queries): start = query[0] end = query[1] if start == 0: results[index] = xor_arr[end] else: results[index] = xor_arr[end] ^ xor_arr[start - 1] return results
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
from itertools import accumulate class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: xors = [0] for a in arr: xors.append(a ^ xors[-1]) return [(xors[i] ^ xors[j + 1]) for i, j in queries]
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR
Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.   Example 1: Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]] Output: [2,7,14,8] Explanation: The binary representation of the elements in the array are: 1 = 0001 3 = 0011 4 = 0100 8 = 1000 The XOR values for queries are: [0,1] = 1 xor 3 = 2 [1,2] = 3 xor 4 = 7 [0,3] = 1 xor 3 xor 4 xor 8 = 14 [3,3] = 8 Example 2: Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]] Output: [8,0,4,4]   Constraints: 1 <= arr.length <= 3 * 10^4 1 <= arr[i] <= 10^9 1 <= queries.length <= 3 * 10^4 queries[i].length == 2 0 <= queries[i][0] <= queries[i][1] < arr.length
class Solution: def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: curr = 0 cum_sum = [] res = [] for n in arr: curr ^= n cum_sum.append(curr) for start, end in queries: x = cum_sum[end] ^ (cum_sum[start - 1] if start > 0 else 0) res.append(x) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
def main(): n, q = map(int, input().split()) binary = ["{:031b}".format(int(i)) for i in input().split()] zero = [[(0) for i in range(n)] for j in range(31)] one = [[(0) for i in range(n)] for j in range(31)] for pos in range(31): ones = 0 zeroes = 0 item_index = 0 for item in binary: if item[pos] == "0": zeroes += 1 elif item[pos] == "1": ones += 1 zero[pos][item_index] = zeroes one[pos][item_index] = ones item_index += 1 for queries in range(q): l, r = map(int, input().split()) ans = "" for pos in range(31): if l == 1: ones = one[pos][r - 1] zeroes = zero[pos][r - 1] else: ones = one[pos][r - 1] - one[pos][l - 2] zeroes = zero[pos][r - 1] - zero[pos][l - 2] if ones < zeroes: ans = ans + "1" elif ones >= zeroes: ans = ans + "0" print(int(ans, 2)) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) s = [int(x) for x in input().split()] prefix = [([0] * 32) for _ in range(n + 1)] for i, num in enumerate(s, 1): for j in range(32): prefix[i][j] += prefix[i - 1][j] + (num & 1) num >>= 1 for _ in range(q): l, r = map(int, input().split()) l -= 1 r -= 1 ans = 0 for i in range(30, -1, -1): ans <<= 1 bit1 = prefix[r + 1][i] - prefix[l][i] bit0 = r - l + 1 - bit1 ans |= int(bit0 > bit1) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = input().split() n, q = [int(n), int(q)] l1 = [int(num) for num in input().split()] b = [] for j in range(q): x, y = input().split() x, y = [int(x), int(y)] b.append([x, y]) l2 = [] prev = 0 temp = [0] * 31 for p in range(n): if p == 0: s1 = format(l1[p], "b") s2 = [] for g in range(31 - len(s1)): s2.append(0) for g in range(31 - len(s1), 31, 1): s2.append(int(s1[g - 31 + len(s1)])) l2.append(s2) temp = s2 else: s1 = format(l1[p], "b") s2 = [] for g in range(31 - len(s1)): s2.append(0) for g in range(31 - len(s1), 31, 1): s2.append(int(s1[g - 31 + len(s1)])) temp = [(x + y) for x, y in zip(temp, s2)] l2.append(temp) for c in range(q): l = b[c][0] r = b[c][1] l3 = ["0"] * 31 t = [] if l == 1: t = l2[r - 1] else: t = [(x - y) for x, y in zip(l2[r - 1], l2[l - 2])] val = r - l + 1 for h in range(0, 31, 1): if t[h] >= val - t[h]: l3.append("0") else: l3.append("1") str1 = "".join(l3) n1 = int(str1, 2) print(n1, end="\n")
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
N, Q = map(int, input().split()) A = list(map(int, input().split())) abi = [list(map(int, format(A[i], "031b"))) for i in range(N)] cd = [[(0) for i in range(31)] for i in range(N + 1)] for i in range(1, N + 1): for j in range(31): cd[i][j] = cd[i - 1][j] + abi[i - 1][j] temp = [(0) for i in range(31)] for query in range(Q): l, r = map(int, input().split()) X = "" for i in range(31): temp[i] = cd[r][i] - cd[l - 1][i] for i in range(31): if temp[i] < r - l + 1 - temp[i]: X += "1" else: X += "0" print(int(X, 2))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
def binary(N): bits = [] while N != 0: bits.append(N % 2) N = int(N / 2) return bits def decimal(bits): val = 0 for bit in bits: val = val * 2 + bit return val N, Q = [int(x) for x in input().strip().split(" ")] A = [binary(int(x)) for x in input().strip().split(" ")] A = [[]] + A max_length = -1 for val in A: max_length = max(max_length, len(val)) for val in A: req_length = max_length - len(val) for _ in range(req_length): val.append(0) for i in range(1, len(A)): for j in range(max_length): A[i][j] += A[i - 1][j] for _ in range(Q): L, R = [int(x) for x in input().strip().split(" ")] bottom = A[R] top = A[L - 1] ans = [] for i in range(max_length): num_ones = bottom[i] - top[i] num_zeroes = R - L + 1 - num_ones if num_zeroes <= num_ones: ans.append(0) else: ans.append(1) first = [(1) for _ in range(31 - len(ans))] ans = first + ans[::-1] print(decimal(ans))
FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST LIST VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) arr = list(map(int, input().split())) bit = [[(0) for i in range(n + 1)] for j in range(32)] for i in range(n): for j in range(31): bit[j + 1][i + 1] = bit[j + 1][i] if arr[i] & 1 << j: bit[j + 1][i + 1] += 1 for i in range(q): l, r = map(int, input().split()) out = 0 for j in range(1, 32): if (r - l + 1) % 2: if bit[j][r] - bit[j][l - 1] <= (r - l + 1) // 2: out += 1 << j - 1 elif bit[j][r] - bit[j][l - 1] < (r - l + 1) // 2: out += 1 << j - 1 print(out)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = list(map(int, input().split())) b = list(map(int, input().split())) a = [[(0) for x in range(n)] for y in range(31)] for j in range(0, 31): if b[0] & 1 << j: a[j][0] = 1 else: a[j][0] = 0 for i in range(1, n): for j in range(0, 31): if b[i] & 1 << j: a[j][i] = a[j][i - 1] + 1 else: a[j][i] = a[j][i - 1] while q > 0: q = q - 1 t = 0 l, r = list(map(int, input().split())) diff = r - l + 1 if l > 1: for i in range(0, 31): c = a[i][r - 1] - a[i][l - 2] if diff - c > c: t = t + (1 << i) else: for i in range(0, 31): c = a[i][r - 1] if diff - c > c: t = t + (1 << i) print(t)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) a = list(map(int, input().split())) a = [list(map(int, format(i, "031b"))) for i in a] sums = [([0] * 31) for i in range(len(a) + 1)] for i in range(1, len(a) + 1): for j in range(31): sums[i][j] = sums[i - 1][j] + a[i - 1][j] for _ in range(q): l, r = map(int, input().split()) ans = [1] * 31 for j in range(31): curr = sums[r][j] - sums[l - 1][j] if curr >= r - l + 1 - curr: ans[j] = 0 ans = [str(i) for i in ans] ans = "".join(ans) print(int(ans, 2))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) l = list(map(int, input().split())) prefix = [([0] * 32) for i in range(n)] for i in range(n): binary = bin(l[i])[2:] length = len(binary) string = [0] * 32 for j in range(length - 1, -1, -1): if binary[j] == "1": string[length - 1 - j] += 1 if i == 0: for j in range(32): prefix[i][j] = string[j] else: for j in range(32): prefix[i][j] = prefix[i - 1][j] + string[j] for _ in range(q): left, right = map(int, input().split()) left -= 1 right -= 1 result = 0 for i in range(32): nset = 0 if left == 0: nset = prefix[right][i] else: nset = prefix[right][i] - prefix[left - 1][i] if nset >= right - left + 1 - nset: result += int(2**i) print(2147483647 - result)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) arr = [int(x) for x in input().split()] new_array = [] for i in range(n): new_array.append([]) for j in range(31): if arr[i] & 1 << j: if i == 0: new_array[i].append(1) else: new_array[i].append(new_array[i - 1][j] + 1) elif i == 0: new_array[i].append(0) else: new_array[i].append(new_array[i - 1][j]) for i in range(q): x, y = map(int, input().split()) new_sum = 1 max1 = 0 mid = (y - x + 1) / 2 for j in range(31): if x == 1: if new_array[y - 1][j] < mid: max1 += new_sum elif new_array[y - 1][j] - new_array[x - 2][j] < mid: max1 += new_sum new_sum *= 2 print(max1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = tuple(map(int, input().split())) a = [0] + list(map(int, input().split())) count = [[int(bool(x & 1 << y)) for y in range(32)] for x in a] for i in range(1, n + 1): count[i] = list(map(sum, zip(count[i], count[i - 1]))) for _ in range(q): l, r = tuple(map(int, input().split())) diff = [] for i in range(32): temp = count[r][i] - count[l - 1][i] if temp > r - l - temp: diff.append(0) else: diff.append(1) num = 0 x = 0 for k in diff[:-1]: num += (1 << x) * k x += 1 print(num)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) a = [int(i) for i in input().split()] one = [[(0) for i in range(31)] for i in range(n)] for i in range(n): for j in range(31): k = 1 if a[i] & 1 << j > 0 else 0 one[i][j] = one[i - 1][j] + k for o in range(q): l, r = map(int, input().split()) ans = 0 for i in range(31): m = one[r - 1][i] - one[l - 2][i] if l > 1 else one[r - 1][i] le = r - l + 1 if m < le - m: ans = ans | 1 << i print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
N, Q = [int(s) for s in input().split()] A = [int(x) for x in input().split()] num_ones = [([0] * 31) for _ in range(len(A))] def preprocess(A): for i, num in enumerate(A): for j in range(31): if num & 1 << j > 0: if i == 0: num_ones[i][30 - j] = 1 else: num_ones[i][30 - j] = num_ones[i - 1][30 - j] + 1 elif i != 0: num_ones[i][30 - j] = num_ones[i - 1][30 - j] preprocess(A) def solve(l, r): ans = 0 for i in range(30, -1, -1): ones = num_ones[r][30 - i] if l - 1 > -1: ones -= num_ones[l - 1][30 - i] zeros = r - l + 1 - ones if zeros > ones: ans |= 1 << i return ans for _ in range(Q): L, R = [(int(s) - 1) for s in input().split()] print(solve(L, R))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR BIN_OP NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) rah = [0] * 31 a = input().split() arr = [] for i in range(len(a)): tmp = int(a[i]) tmp_l = rah[:] j = 30 while tmp > 0: tmp_l[j] = tmp % 2 j -= 1 tmp //= 2 arr.append(tmp_l) arr_f = [] arr_f.append(rah[:]) arr_f.append(arr[0]) for i in range(1, len(arr)): tmp_l = rah[:] for j in range(len(tmp_l)): tmp_l[j] = arr[i][j] + arr_f[len(arr_f) - 1][j] arr_f.append(tmp_l) for tp in range(q): l, r = map(int, input().split()) f_ans = 0 cou = r - l + 1 for j in range(31): if (arr_f[r][j] - arr_f[l - 1][j]) * 2 < cou: f_ans += pow(2, 30 - j) print(f_ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) A = list(map(int, input().split())) count = [[(0) for col in range(n)] for row in range(31)] b = [bin(x)[2:][::-1] for x in A] for i in range(n): for j in range(len(b[i])): if b[i][j] == "1": count[j][i] = 1 for i in range(31): for j in range(1, n): count[i][j] += count[i][j - 1] for _ in range(q): l, r = map(int, input().split()) out = 0 for i in range(31): if l == 1: c = count[i][r - 1] else: c = count[i][r - 1] - count[i][l - 2] if c < r - l + 1 - c: out += 1 << i print(out)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
res = [] def binaryRep(inum): return "{0:031b}".format(int(inum)) n, q = input().split(" ") n = int(n) q = int(q) nums = input().split(" ") binLen = 31 rowOp = [0] * binLen binMatrix = list(map(binaryRep, nums)) prefixArr = [] prefixArr.append([0] * binLen) for i in range(0, n): temp = [0] * binLen for j in range(0, binLen): if binMatrix[i][j] == "1": rowOp[j] += 1 temp[j] = rowOp[j] prefixArr.append(temp) for k in range(0, q): l, r = input().split(" ") l = int(l) r = int(r) half = int((r - l) / 2) fnum = 0 for c in range(0, binLen): ones = prefixArr[r][c] - prefixArr[l - 1][c] if ones <= half: fnum += pow(2, binLen - 1 - c) res.append(fnum) for xx in res: print(xx)
ASSIGN VAR LIST FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR STRING VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
def solve(): N, Q = map(int, input().split()) nums = list(map(int, input().split())) WIDTH = 31 def doMatrix(nums): matrix = [([0] * WIDTH) for _ in range(N)] for i, k in enumerate(nums): row = matrix[i] for j in range(WIDTH): row[j] = k >> WIDTH - 1 - j & 1 return matrix matrix = doMatrix(nums) preSum = [([0] * WIDTH) for _ in range(N + 1)] for j in range(WIDTH): for i in range(1, len(preSum)): preSum[i][j] = preSum[i - 1][j] + matrix[i - 1][j] for _ in range(Q): L, R = map(int, input().split()) n = R - L + 1 half = n / 2 - 0.1 rowL = preSum[L - 1] rowR = preSum[R] row = [(b - a) for a, b in zip(rowL, rowR)] res = ["1"] * WIDTH for i in range(WIDTH): if row[i] >= half: res[i] = "0" print(int("".join(res), 2)) T = 1 for _ in range(T): solve()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) l = list(map(int, input().split())) k = [[0] * 31] x = "{0:031b}" for i in range(n): s = x.format(l[i]) s = s[-1::-1] c = [] for j in range(31): c.append(k[-1][j] + int(s[j])) k.append(c) for _ in range(q): a, r = map(int, input().split()) a -= 1 ans = 0 c = 1 d = [] for i in range(31): d.append(k[r][i] - k[a][i]) e = r - a s = "" for i in d: if i >= e - i: s += "0" else: s += "1" s = s[-1::-1] print(int(s, 2))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP LIST NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING FOR VAR VAR IF VAR BIN_OP VAR VAR VAR STRING VAR STRING ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) w = [[(0) for i in range(31)] for j in range(n)] a = [*map(int, input().split())] for i in range(n): p = 0 j = a[i] while j: w[i][p] += j & 1 j >>= 1 p += 1 w = [[0] * 31] + w for i in range(1, n + 1): for j in range(31): w[i][j] += w[i - 1][j] for i in range(q): x, y = map(int, input().split()) ans = 0 for j in range(31): if w[y][j] - w[x - 1][j] < y - x + 2 >> 1: ans += 1 << j print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP LIST NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = input().split() n, q = [int(n), int(q)] p = list(map(int, input().split())) emp = [] for lm in range(0, q): l, r = list(map(int, input().split())) emp.append([l, r]) a = [] c = [] b = [0] * 31 for i in range(0, n): a.append([int(rs) for rs in list("{0:031b}".format(p[i]))]) c.append(a[0]) for i in range(1, len(a)): c.append([sum(x) for x in zip(a[i], c[i - 1])]) for ps in range(0, q): tt = [] tat = [] la = emp[ps][0] ra = emp[ps][1] if la == 1: tt = c[ra - 1] else: tt = [(x - y) for x, y in zip(c[ra - 1], c[la - 2])] for qs in range(0, 31): if ra - la + 1 - tt[qs] > tt[qs]: tat.append("1") else: tat.append("0") pqr = "".join(tat) jkl = int(pqr, 2) print(jkl)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
import sys def makeMatch(l): l.sort() res, cnt = [], 1 for i in range(1, len(l)): if l[i] == l[i - 1]: cnt += 1 else: res.append((l[i - 1], cnt)) cnt = 1 if i == len(l) - 1: res.append((l[i], cnt)) return sorted(res, key=lambda x: (x[1], x[0])) n, q = [int(x) for x in sys.stdin.readline().split()] l = [int(n) for n in sys.stdin.readline().split()] b = [] m = 0 for i in range(n): t, tle = [], [int(x) for x in list(bin(l[i])[2:])] for i in range(32 - len(tle)): t.append(0) t += tle[:] if m < len(tle): m = len(t) b.append(t) for i in range(1, n): b[i] = [(fi + se) for fi, se in zip(b[i], b[i - 1])] for _ in range(q): r = [int(x) for x in sys.stdin.readline().split()] d = r[1] - r[0] s = [None] * m chk = d // 2 for i in range(m): if r[0] == 1: if b[r[1] - 1][i] <= chk: s[i] = 0 else: s[i] = 1 elif b[r[1] - 1][i] - b[r[0] - 2][i] <= chk: s[i] = 0 else: s[i] = 1 ans = 0 for i in range(m): ans += 2**i * s[m - i - 1] print(2147483647 - ans)
IMPORT FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
N, Q = [int(i) for i in input().split(" ")] List = [int(i) for i in input().split(" ")] List1 = [[(0) for i in range(31)]] Final_List1 = [] temp = 0 for i in List: Final_List = list(map(int, list(str("{0:031b}".format(i))))) Final_List1 = [] for j in range(31): Final_List1.append(Final_List[j] + List1[temp][j]) List1.append(Final_List1) temp += 1 for _ in range(Q): L, R = [int(i) for i in input().split(" ")] num = (R - L + 1) / 2 Final_List2 = [] for j in range(31): if num <= List1[R][j] - List1[L - 1][j]: Final_List2.append("0") else: Final_List2.append("1") print(int("".join(Final_List2), 2))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = [int(x) for x in input().split()] psum = [[0] * 31] c = 0 for numl in [list(map(int, bin(int(x))[2:].zfill(31))) for x in input().split()]: psum.append([(x + y) for x, y in zip(psum[c], numl)]) c += 1 def shifting(bitlist): out = 0 for bit in bitlist: out = out << 1 | bit return out while q: l, r = [int(x) for x in input().split()] setbits = [(y - x) for x, y in zip(psum[l - 1], psum[r])] size = r - l + 1 bitarr = [(0 if setbits[i] >= size / 2 else 1) for i in range(31)] print(shifting(bitarr)) q -= 1
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
POWS = [1] for i in range(32): POWS.append(POWS[-1] * 2) def b(S, bit, l, r): return S[bit][r + 1] - S[bit][l] def max_bits(S, l, r): x = 0 length = r - l + 1 for bit in range(31): if b(S, bit, l, r) < length / 2: x += POWS[bit] return x N, Q = map(int, input().split()) A = list(map(int, input().split())) S = [[(0) for i in range(N + 1)] for i in range(32)] for bit in range(32): for i in range(N): S[bit][i + 1] = S[bit][i] + (A[i] & POWS[bit] != 0) for i in range(Q): l, r = map(int, input().split()) print(max_bits(S, l - 1, r - 1))
ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) arr = list(map(int, input().split())) prefixsum = [[0] * 31] for i in range(len(arr)): binary = "{0:031b}".format(arr[i]) t = [] for j in range(31): t.append(prefixsum[i][j] + int(binary[j])) prefixsum.append(t) for i in range(q): l, r = map(int, input().split()) count0 = 0 count1 = 0 binary = "" for j in range(31): count1 = prefixsum[r][j] - prefixsum[l - 1][j] count0 = r - l + 1 - count1 if count1 >= count0: binary += "0" else: binary += "1" print(int(binary, 2))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, Q = map(int, input().split()) arr = [0] + [int(_) for _ in input().split()] prefix = [[(0) for _ in range(31)] for _ in range(n + 1)] for i in range(1, n + 1): for j in range(31): prefix[i][j] = prefix[i - 1][j] + (arr[i] & 1 << j == 0) for _ in range(Q): ans = 0 l, r = map(int, input().split()) for j in range(31): cnt0 = prefix[r][j] - prefix[l - 1][j] cnt1 = r - l + 1 - cnt0 if cnt1 < cnt0: ans += 1 << j print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) l = [int(i) for i in input().split()] pre = [[(0) for j in range(n)] for i in range(31)] for i in range(31): if l[0] & 1 << i: pre[i][0] = 1 else: pre[i][0] = 0 for i in range(31): for j in range(n): if l[j] & 1 << i: pre[i][j] = pre[i][j - 1] + 1 else: pre[i][j] = pre[i][j - 1] for _ in range(q): le, r = map(int, input().split()) le = le - 1 r = r - 1 ans = 0 for i in range(31): seg = r - le + 1 if le == 0: ones = pre[i][r] else: ones = pre[i][r] - pre[i][le - 1] zeroes = seg - ones if zeroes > ones: ans += pow(2, i) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
N, Q = [int(x) for x in input().split()] A = [int(x) for x in input().split()] A = list(map(lambda n: [(n >> i & 1) for i in range(31)], A)) B = [] B.append(A[0]) for i in range(1, N): T = [] for j in range(31): T.append(A[i][j] + B[i - 1][j]) B.append(T) for i in range(Q): l, r = [int(x) for x in input().split()] l, r = l - 1, r - 1 T = [] to_app = [0] * 31 if l == 0 else B[l - 1] c_sum = 0 for j in range(30, -1, -1): c_sum |= 0 if 2 * (B[r][j] - to_app[j]) >= r - l + 1 else 1 c_sum <<= 1 print(c_sum >> 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER BIN_OP LIST NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
N, Q = list(map(int, input().split())) ai = list(map(int, input().split())) binary = [] t_count = [] for i in range(N): t = [] for g in range(31): t.append(0) t_count.append(t) binary.append(bin(ai[i])[2:]) binary[i] = "0" * (31 - len(binary[i])) + binary[i] if i != 0: for g in range(31): t_count[i][g] = t_count[i - 1][g] + int(binary[i][g]) else: for g in range(31): t_count[0][g] = int(binary[0][g]) for i in range(Q): L, R = list(map(int, input().split())) L = L - 1 R = R - 1 t = "" if L == 0: for h in range(31): a = t_count[R][h] / (R - L + 1) if a < 0.5: t += "1" else: t += "0" else: for h in range(31): b = (t_count[R][h] - t_count[L - 1][h]) / (R - L + 1) if b < 0.5: t += "1" else: t += "0" print(int(t, 2))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
n, q = map(int, input().split()) a = list(map(int, input().split())) b = [format(x, "031b") for x in a] c1 = [[0] * 31] for i in range(n): temp = [] for j in range(31): temp.append(c1[i][j] + int(b[i][j])) c1.append(temp) for i in range(q): l, r = map(int, input().split()) res = "" tc = r - l + 1 for j in range(31): co1 = c1[r][j] - c1[l - 1][j] co0 = tc - co1 if co0 > co1: res += "1" else: res += "0" print(int(res, 2))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING VAR VAR ASSIGN VAR LIST BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
strInp = input() n, q = strInp.split() n = int(n) q = int(q) a = list(map(int, input().split())) sums = [] mask = 1073741824 current = [] while mask: bit = int(a[0] & mask > 0) current.append(bit) mask >>= 1 sums.append(current) previous = current for i in range(1, n): current = [] mask = 1073741824 j = 0 while mask: bit = int(a[i] & mask > 0) current.append(bit + previous[j]) j += 1 mask >>= 1 sums.append(current) previous = current while q != 0: strInp = input() left, right = strInp.split() left = int(left) right = int(right) numbers = right - left + 1 left -= 1 right -= 1 xorValue = 0 mask = 1073741824 for i in range(31): if left != 0: numOfOnes = sums[right][i] - sums[left - 1][i] else: numOfOnes = sums[right][i] numOfZeros = numbers - numOfOnes if numOfZeros > numOfOnes: xorValue |= mask mask >>= 1 print(xorValue) q -= 1
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
def padd(arr, l): for i in range(len(arr)): arr[i] = arr[i] + "0" * (l - len(arr[i])) return arr n, m = map(int, input().split()) a = map(int, input().split()) a = [bin(i)[2:][::-1] for i in a] mm = max(len(i) for i in a) a = padd(a, mm) ans = [[] for i in range(n)] ans[0] = [int(i) for i in a[0]] max1 = 0 qq = [] for _ in range(m): l, r = map(int, input().split()) max1 = max(max1, r) qq.append((l, r)) for j in range(mm): for i in range(1, len(a)): if len(a[i]) > j: if a[i][j] == "1": ans[i].append(ans[i - 1][j] + 1) else: ans[i].append(ans[i - 1][j]) for q in qq: l, r = q an = ["1" for _ in range(31)] for i in range(mm): if l > 1: if ans[r - 1][i] - ans[l - 2][i] >= (r - l + 1) / 2: an[i] = "0" elif ans[r - 1][i] >= r / 2: an[i] = "0" print(int("".join(an[::-1]), 2))
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
def preprocess(mat, arr, n): for i in range(n): b = bin(arr[i]) b = b[2:] m = len(b) for j in range(m): if b[j] == "1": mat[i][31 - m + j] += 1 for i in range(1, n): for j in range(31): mat[i][j] += mat[i - 1][j] return mat def diff(arr1, arr2): arr = [] for i in range(31): arr.append(arr1[i] - arr2[i]) return arr n, q = map(int, input().strip().split()) arr = list(map(int, input().strip().split())) mat = [] for i in range(n): a = [] for i in range(31): a.append(0) mat.append(a) mat = preprocess(mat, arr, n) for i in range(q): l, r = map(int, input().strip().split()) d = r - l + 1 if l == 1: ans = mat[r - 1] else: ans = diff(mat[r - 1], mat[l - 2]) s = "" for i in range(31): if ans[i] >= d - ans[i]: s += "1" else: s += "0" print(2**31 - 1 - int(s, 2))
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
lim = 31 n, q = map(int, input().split()) arr = list(map(int, input().split())) bits = [([0] * (n + 1)) for _ in range(lim)] def initialize(): for i in range(n): x = arr[i] for j in range(lim): mask = 1 << j bits[j][i] += bits[j][i - 1] if mask & x: bits[j][i] += 1 initialize() for _ in range(q): l, r = map(lambda x: int(x) - 1, input().split()) ans = 0 nums = r - l + 1 for i in range(lim): count = bits[i][r] - bits[i][l - 1] if count < (nums + 1) // 2: ans += 1 << i print(ans)
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X < 2^{31} and the value of (A_{L} xor X) + (A_{L+1} xor X) + ... + (A_{R} xor X) is maximum possible. Note: xor denotes the bitwise xor operation. ------ Input ------ The first line of the input contains two space-separated integers N and Q denoting the number of elements in A and the number of queries respectively. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N}. Each of the next Q lines contains two space-separated integers L and R describing one query. ------ Output ------ For each query, print a single line containing one integer — the minimum value of X. ------ Constraints ------ $1 ≤ N ≤ 10^{5}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ A_{i} < 2^{31} for each valid i$ ------ Subtasks ------ Subtask #1 (18 points): $1 ≤ N ≤ 10^{3}$ $1 ≤ Q ≤ 10^{3}$ $0 ≤ A_{i} < 2^{10} for each valid i$ Subtask #2 (82 points): original constraints ----- Sample Input 1 ------ 5 3 20 11 18 2 13 1 3 3 5 2 4 ----- Sample Output 1 ------ 2147483629 2147483645 2147483645
def binaryde(a): return "{0:b}".format(a) n, q = list(map(int, input().split())) llist = list(map(int, input().split())) sub = 2**31 kitnezeroes = [] templist = [] for x in range(31): zeroes = 0 sub /= 2 templist = [] for y in range(n): if llist[y] - sub < 0: zeroes += 1 else: llist[y] -= sub templist.append(zeroes) kitnezeroes.append(list(templist)) for i in range(q): l, r = list(map(int, input().split())) kitneelements = r - l + 1 ans = "" zeroes = 0 for j in range(31): if l - 2 < 0: zeroes = kitnezeroes[j][r - 1] else: zeroes = kitnezeroes[j][r - 1] - kitnezeroes[j][l - 2] if zeroes > kitneelements // 2: ans = ans + "1" else: ans = ans + "0" print(int(ans, 2))
FUNC_DEF RETURN FUNC_CALL STRING VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER