what happens when you take the XOR of whole array with an element
what to do in the case when the XOR of the array is zero
Compute the XOR of the whole array, what happen when the XOR of the whole array is ZERO the ans is YES.
If the XOR is not zero then from which number we should XOR that it becames zero
If XOR of the whole array is X if X^a[i]=0 then X=a[i] as removing the element for the array is same as XORing it again,
then if X (XOR of the whole array) is present in the array then we can remove it and then make the XOR zero else the ans is NO
675587B - The magical operation
If a element doesn't divide x now, will it ever divide it ever ?
if it divides x now and get multiplied with y at max how many times it will get updated (Remember then the element will never exceed 1e18 limit)
what about the case in which y==1
lets assume their is a magical x which is divisible by every number then how many times a single element will get updated if y>1 -- at max 60.
when y==1 then just skip the operation because it will not updated any number.
what about when y is not one and also and element is not updated because x%a[i]!=0.
If initially x%a[i]!=0 then it will never be divisible after any update.
lets assume two number X and Y if X%Y==0 then every factor of Y will also divides X
but if a factor of Y doesn't divides X then will Y also not divide X.
If a is not a factor of X then a*b will also be not the factor of X.
For every distinct value $$$x$$$, we store all indices $$$i$$$ where $$$x$$$ is divisible by $$$a[i]$$$.
We remove an index $$$i$$$ from the set once $$$x$$$ is no longer divisible by $$$a[i]$$$
The total complexity to remove indices across all operations is $$$O(n)$$$
If $$$x$$$ is divisible by $$$a[i]$$$, the total complexity is $$$O(32 \cdot n)$$$ for $$$y \gt 1$$$ (since $$$x \le 2 \cdot 10^9$$$, an element can be divided at most 31 times)
If $$$y = 1$$$, we skip the operation entirely.Since the number of distinct values of $$$x$$$ is $$$\le 500$$$, this approach is efficient and stays within time limits.
675587C - Ashutosh and his dreams
think from the back
now when you add x, can you know what value it will get converted to at the end.
The trick lies in processing the queries in reverse.Think about it: an element added at query $$$i$$$ is only affected by Type 2 operations that occur after query $$$i$$$. If we know what a value $$$v$$$ "eventually becomes" by the end of all queries, we can immediately determine the final value of any number we append.
Create an array (let's call it parent or f) where f[v] represents what the value $$$v$$$ currently transforms into. Initially, f[v] = v for all $$$v$$$ up to the maximum possible value ($$$3 \cdot 10^5$$$).
Start from the $$$q$$$-th query and work back to the 1st.
Process Type 2 ($$$2, x, y$$$): In reverse, this operation means that any $$$x$$$ existing before this point will eventually be treated as $$$x + y$$$.Update the mapping: f[x] = f[x + y].
Process Type 1 ($$$1, x$$$):When we "add" $$$x$$$ (in reverse, this is the moment the element was born), its final value is whatever f[x] is at that moment.Store f[x] in a result list.
Since we processed Type 1 queries from last to first, reverse your result list and print it.
this the question of invariance
multiply the x and the y coordinate
The Core Invariants To solve this
we need to find a function $$$f(x, y)$$$ such that the XOR sum of $$$f$$$ over the four points of the operation is always zero:
Unable to parse markup [type=CF_MATHJAX]
\mathbf{s = \bigoplus_{i=1}^n x_i}
Unable to parse markup [type=CF_MATHJAX]
(f(P_1) \oplus f(P_3)) \oplus (f(P_2) \oplus f(P_4)) = 0 \oplus 0 = 0$$
This proves that the XOR sum of the products $$$(x_i \cdot y_i)$$$ is also an invariant!
Calculate the bitwise XOR sum of all $$$x_i$$$ coordinates to find $$$s$$$:
Unable to parse markup [type=CF_MATHJAX]
\mathbf{t = V / s}
Unable to parse markup [type=CF_MATHJAX]
, as we iterate through the list of active cells once.Space: $$$O(1)$$$ additional space beyond storing the input.675587E1][PROBLEM:675587E2 - Holi Tree (Easy Version)
try to convert the tree in an array
euler tour(remove the 2nd occurence)
now you have a path in what range will the subtree of i lies
Randomized Algorithm
By performing a DFS Traversal, we can assign each vertex an entry time (tin) and exit time (tout).The subtree rooted at $$$i$$$ now corresponds to a contiguous range in the DFS-order array: [tin[i], tout[i]].The size of the subtree $$$sz$$$ is simply tout[i] — tin[i] + 1.
now the range of subtree of $$$i$$$ will lies in range pos[i] to pos[i]+subtree[i];
now we can apply a randomize search in this range
if their exist a colour which is more then 1/3rd of the time if we randomly check the colour the probability that it will not be chosen is 2/3 if we perform this operation 50 times then its very low that we may not choose a vertices whose colour appears more then 1/3 time
now for every query do 50+ times randomize approach then for the colour of random vertices see the freq. of that colour in the range which can be done by binary search..
you will store the tin tout time of the vertices for every colour then sort the vector
then do
can you just remove the vertices for the current colour and put it in the new colour
use ordered_set instead of vector
read the solution for the easy version
now for the 2nd type of query you can use ordered set instead of the vector and then can erase and insert the colour according to the update and to count the frequency use this
try to do it with Misra-Gries Algorithm.



