Exemplo n.º 1
0
        static void Main(string[] args)
        {
            tests        new_tests = new tests();
            Stopwatch    stopWatch = new Stopwatch();
            StreamReader input_stream = new StreamReader("input.txt");
            StreamWriter output_stream = new StreamWriter("output.txt");
            int          N, K;

            int[] length_array;
            while (!input_stream.EndOfStream)
            {
                string[] input = input_stream.ReadLine().Split(' ');
                N            = Int32.Parse(input[0]);
                K            = Int32.Parse(input[1]);
                length_array = new int[N];
                for (int i = 0; i < N; i++)
                {
                    length_array[i] = Int32.Parse(input_stream.ReadLine());
                }
                stopWatch.Restart();
                Array.Sort(length_array);
                output_stream.WriteLine(BinarySearch(length_array, K));
                output_stream.WriteLine(stopWatch.Elapsed);
            }
            input_stream.Close();
            output_stream.Close();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            tests        tests = new tests();
            StreamReader input_stream = new StreamReader("input.txt");
            StreamWriter output_stream = new StreamWriter("output.txt");
            Stopwatch    stopWatch = new Stopwatch();
            int          num_of_objects, num_of_request;
            List <int[]> tree;

            string[] input;
            while (!input_stream.EndOfStream)
            {
                input          = input_stream.ReadLine().Split(' ');
                num_of_objects = Int32.Parse(input[0]);
                num_of_request = Int32.Parse(input[1]);
                tree           = new List <int[]>();
                tree.Add(new int[num_of_objects]);
                for (int i = 0; i < num_of_objects; i++)
                {
                    tree[0][i] = Int32.Parse(input_stream.ReadLine());
                }
                stopWatch.Restart();
                fillTheTree(tree);
                for (int i = 0; i < num_of_request; i++)
                {
                    input = input_stream.ReadLine().Split(' ');
                    if (input[0] == "1")
                    {
                        output_stream.WriteLine(sumRequest(tree, input));
                    }
                    else
                    {
                        updateRequest(tree, input);
                    }
                }
                output_stream.WriteLine(stopWatch.Elapsed);
            }

            input_stream.Close();
            output_stream.Close();
        }