ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 2030. Защитная Бэкап-Система

Time limit
Послано Snowball_TverSU 22 ноя 2014 23:49
Hello everyone. I always receive time limit on Test №21. Could you give any hints? Maybe  this task requires special data structure (I try to represent tree as list of edges or adjacency list) or there is interesting algorythm? Thanks for reading.
Re: Time limit
Послано Tolstobrov Anatoliy[Ivanovo SPU] 3 дек 2014 20:47
Not update connected vertexes for vertexes with amount of connections more than Sqrt(N).
In this case sum for vertex will be current sum + delta for connected vertexes with size more than Sqrt(N).
Re: Time limit
Послано Mikhail Krivenko 6 дек 2014 01:01
I have the same problem with TLE #21 and I can't understand your hint: what's that 'delta', how can I track/calculate it?

I realize that the bottleneck is in vertices with high amount of linked edges but I can't understand how to avoid them - I still need update all vertices, otherwise I loose data for next steps.
Re: Time limit
Послано daniel_de_darik 6 дек 2014 17:03
yes, you're right about data structure. I used binary indexed tree to solve the problem. Overall complexity is O(n + m * logn). So, you actually preprocess data in O(n) time and for each query you spent O(logn) time, which perfectly fits time constraints of the problem
Re: Time limit
Послано Adhambek 30 дек 2014 17:58
my algo is O(n+m)
Re: Time limit
Послано Sunnat 15 янв 2015 16:33
I agree with you