83012024-01-14 12:35:56ananászBináris fa magassága (50 pont)csharpTime limit exceeded 20/50584ms24756 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace binfa2
{
    class Program
    {
        struct pont
        {
            public int elso;
            public int utolso;
            public int suly;
        }
        static void Main(string[] args)
        {
            string[] st = Console.ReadLine().Split();
            int N = int.Parse(st[0]);
            int M = int.Parse(st[1]);
            int db = (int)Math.Pow(2, N) - 1;
            pont[] hossz = new pont[db];
            int szint = 1;
            int id = 1;
            while (szint < N)
            {
                db = (int)Math.Pow(2, szint);
                int y = (int)Math.Pow(2, N - 1 - szint);
                for (int i = 0; i < db; i++)
                {
                    hossz[id].suly = 1;
                    hossz[id].elso = i * y;
                    hossz[id].utolso = (i + 1) * y - 1;
                    id++;
                }
                szint++;
            }
            int[] utolso = new int[(int)Math.Pow(2, N - 1)];
            for (int i = 0; i < utolso.Length; i++)
            {
                utolso[i] = N - 1;
            }
            List<int> magassag = new List<int>();
            int max = 1;
            for (int i = 0; i < M; i++)
            {
                st = Console.ReadLine().Split();
                int el = int.Parse(st[0]) - 1;
                int hossza = int.Parse(st[1]);
                int valtozas = hossza - hossz[el].suly;
                hossz[el].suly = hossza;
                if (valtozas > 0)
                {
                    for (int j = hossz[el].elso; j <= hossz[el].utolso; j++)
                    {
                        if (max < utolso[j] + valtozas)
                        {
                            max = utolso[j] + valtozas;
                        }
                        utolso[j] += valtozas;
                    }
                }
                else if (valtozas < 0)
                {
                    for (int j = hossz[el].elso; j <= hossz[el].utolso; j++)
                    {
                        utolso[j] += valtozas;
                    }
                    max = utolso.Max();

                }
                magassag.Add(max);
            }
            foreach (var item in magassag)
            {
                Console.WriteLine(item);
            }
            Console.ReadKey();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/030ms22144 KiB
2Time limit exceeded0/0578ms6072 KiB
3Accepted2/237ms23524 KiB
4Accepted2/237ms23888 KiB
5Accepted2/237ms23732 KiB
6Accepted2/237ms23696 KiB
7Accepted3/337ms23872 KiB
8Accepted3/339ms23832 KiB
9Accepted3/337ms24464 KiB
10Accepted3/341ms24756 KiB
11Time limit exceeded0/2533ms9264 KiB
12Time limit exceeded0/2569ms9532 KiB
13Time limit exceeded0/2560ms10064 KiB
14Time limit exceeded0/2580ms9960 KiB
15Time limit exceeded0/2555ms10100 KiB
16Time limit exceeded0/2572ms8792 KiB
17Time limit exceeded0/2560ms8688 KiB
18Time limit exceeded0/2552ms8948 KiB
19Time limit exceeded0/2564ms9272 KiB
20Time limit exceeded0/3584ms10976 KiB
21Time limit exceeded0/3564ms10872 KiB
22Time limit exceeded0/3560ms11112 KiB
23Time limit exceeded0/3569ms11596 KiB