Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Create a list, seqList , of N empty sequences, where each sequence is indexed from 0 to N - 1. The elements within each of the N sequences also use 0-indexing.
- Create an integer, lastAnswer, and initialize it to 0.
- The types of queries that can be performed on your list of sequences () are described below:
- Query: 1 x y
- Find the sequence, seq, at index (x ^ lastAnswer) % N in seqList.
- Append integer y to sequence seq.
- Query: 2 x y
- Find the sequence, seq, at index (x ^ lastAnswer) % N in seqList.
- Find the value of element y % size in seq (where size is the size of seq) and assign it to lastAnswer.
- Print the new value of lastAnswer on a new line*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _54_DynamicArray
- {
- class DynamicArray
- {
- static void Main(string[] args)
- {
- int[] initialData = Console.ReadLine()
- .Split(' ')
- .Select(int.Parse)
- .ToArray();
- List<List<int>> seqList = new List<List<int>>(initialData[0]);
- for (int i = 0; i < initialData[0]; i++)
- {
- seqList.Add(new List<int>());
- }
- int lastAnswer = 0;
- for (int i = 0; i < initialData[1]; i++)
- {
- int[] data = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- if (data[0] == 1)
- {
- seqList[(data[1] ^ lastAnswer) % seqList.Count].Add(data[2]);
- }
- else
- {
- lastAnswer = seqList[(data[1] ^ lastAnswer) % seqList.Count][data[2] % seqList[(data[1] ^ lastAnswer) % seqList.Count].Count];
- Console.WriteLine(lastAnswer);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment