Want to know Hint for Question : Google India Summer Internship Program 2021 — Coding Test — 16 August (Ended)

Revision en3, by CodingBeast23, 2020-08-21 17:19:23

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..

Tags #google

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English CodingBeast23 2020-08-21 17:19:23 750
en2 English CodingBeast23 2020-08-21 16:49:11 8
en1 English CodingBeast23 2020-08-21 16:48:02 591 Initial revision (published)