• + 0 comments

    С# solution (Half of difficulty its figure out what the task is actually...)

    Task explanation(if someone needed): We have an input : [[type, x, y]] , where type - type of queries( if 1 - add y in list(using formula), if 2 - extract element using second formula and add to lastAnswer ). x - parametr, what we using in formula which calculate index where we need to insert/extract y. y - parameter, what we insert/extract.

    {
        List<List<int>> seqList = new List<List<int>>();
        for (int i = 0; i < n; i++)
        {
            seqList.Add(new List<int>());
        }
    
        List<int> results = new List<int>();
        int lastAnswer = 0;
    
        foreach (var query in queries)
        {
            int type = query[0];
            int x = query[1];
            int y = query[2];
            int seqIndex = (x ^ lastAnswer) % n;
    
            if (type == 1)
            {
                seqList[seqIndex].Add(y);
            }
            else if (type == 2)
            {
                int size = seqList[seqIndex].Count;
                lastAnswer = seqList[seqIndex][y % size];
                results.Add(lastAnswer);
            }
    
        }
    
        return results;
    }