Problem Statement`` ================= : Given a list which initially contains 0, the following queries can be performed:
0 X : Add X to the List
1 X : Replace each element in List With its XOR with X (i.e. Replace A with A^X where is ^ is an XOR operation)
Return a list in increasing order after all queries.
-------- Sample :
-------- Q=5
0 4
0 2
1 4
0 5
1 8
Answer : 8 12 13 14
Let me know the concept in this problem :
Thanks.
Update : Got The Solution : Thanks
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
signed main()
{
vector<int>v;
int effect=0;
int q;
cin >> q;
v.push_back(0);
while(q--)
{
int type,x;
cin >> type >> x;
if(type==0)
{
v.push_back(x);
v.back()^=effect;
}
else
{
effect^=x;
}
}
for(int i=0;i<v.size();i++)
{
v[i]^=effect;
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
cout<<v[i]<<' ';
}
Thanks CodeForces Community ... This Was my First Attempt to CF Blogs..