Блог пользователя minhi1

Автор minhi1, история, 8 месяцев назад, По-английски

Given a tree with n nodes and n — 1 edges. There are total k different colors (k <= n). Each node i has a color c(i) (1 <= c(i) <= k). Cost of a subtree u equals number of distinct colors in subtree u.

Given q queries. Each query belongs to two types: Type 1: (1, u, nw) is to change the color of node u to nw. (1 <= nw <= k) Type 2: (2, u) print the Cost of subtree u.

Constraints: 1 <= n <= 5e5 1 <= q <= 3e5

So far I have only thought of counting distinct colors without updating queries by small-to-large or BIT. For updating, I just know that type 1 query will affect all the ancestors of u. Still, I don't know the optimized way yet. Can you guys help me ? Thanks.

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор minhi1, история, 10 месяцев назад, По-английски

Given a connected graph with n nodes and m edges (n, m <= 1e5). There are q queries (q <= 1e5), each has type of (u, d, c) means to color all nodes which have the smallest distance to u <= d color c (d <= 10, c <= 1e5). What is the color of n nodes after q queries.

I can only do smaller subtask when n,m,q <= 2000 with bfs. I do think about solving queries backward and color nodes that are empty but still don't know how to optimize it. Can anyone help me. Thanks.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится