codeforces620enewyeartree(线段树的骚操作第二弹)(代码片段)

Styx-ferryman Styx-ferryman     2022-11-07     617

关键词:

The New Year holidays are over, but Resha doesn‘t want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree.

The New Year tree is an undirected tree with n vertices and root in the vertex 1.

You should process the queries of the two types:

  1. Change the colours of all vertices in the subtree of the vertex v to the colour c.
  2. Find the number of different colours in the subtree of the vertex v.
Input

The first line contains two integers n, m (1 ≤ n, m ≤ 4·105) — the number of vertices in the tree and the number of the queries.

The second line contains n integers ci (1 ≤ ci ≤ 60) — the colour of the i-th vertex.

Each of the next n - 1 lines contains two integers xj, yj (1 ≤ xj, yj ≤ n) — the vertices of the j-th edge. It is guaranteed that you are given correct undirected tree.

The last m lines contains the description of the queries. Each description starts with the integer tk (1 ≤ tk ≤ 2) — the type of the k-th query. For the queries of the first type then follows two integers vk, ck (1 ≤ vk ≤ n, 1 ≤ ck ≤ 60) — the number of the vertex whose subtree will be recoloured with the colour ck. For the queries of the second type then follows integer vk (1 ≤ vk ≤ n) — the number of the vertex for which subtree you should find the number of different colours.

Output

For each query of the second type print the integer a — the number of different colours in the subtree of the vertex given in the query.

Each of the numbers should be printed on a separate line in order of query appearing in the input.

Examples
input
7 10
1 1 1 1 1 1 1
1 2
1 3
1 4
3 5
3 6
3 7
1 3 2
2 1
1 4 3
2 1
1 2 5
2 1
1 6 4
2 1
2 2
2 3
output
2
3
4
5
1
2
input
23 30
1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6
1 2
1 3
1 4
2 5
2 6
3 7
3 8
4 9
4 10
4 11
6 12
6 13
7 14
7 15
7 16
8 17
8 18
10 19
10 20
10 21
11 22
11 23
2 1
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 4
1 12 1
1 13 1
1 14 1
1 15 1
1 16 1
1 17 1
1 18 1
1 19 1
1 20 1
1 21 1
1 22 1
1 23 1
2 1
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 4
output
6
1
3
3
2
1
2
3
5
5
1
2
2
1
1
1
2
3

题意:来自费老先生的翻译
你有一棵以1为根的有根树,有n个点,每个节点初始有一个颜色c[i]。


有两种操作:

1 v c 将以v为根的子树中所有点颜色更改为c

2 v 查询以v为根的子树中的节点有多少种不同的颜色


题解:来自蒟蒻xhk的题解:

我们看到这道题的颜色最多只有60种,所以理所应当的想到突破口就是颜色,60的范围可以考虑状压,其实我们在乎的只是有或者没有该颜色,所以我们可以用或运算来合并两个块,这自然是线段树的思路,

因为只有修改子树或者查询子树的操作,所以直接dfs序就可以啦~
对dfs序维护一个线段树,支持区间修改区间或,统计区间或之后得到的数在二进制下1的个数,这即为答案



codeforces620enewyeartree(线段树的骚操作第二弹)(代码片段)

TheNewYearholidaysareover,butReshadoesn‘twanttothrowawaytheNewYeartree.HeinvitedhisbestfriendsKerimandGuraltohelphimtoredecoratetheNewYeartree.TheNewYeartreeisanundirectedtreewith n vertices 查看详情

codeforces620enewyeartree(代码片段)

题目大意你有一棵以1为根的有根树,有n个点,每个节点初始有一个颜色c[i]。有两种操作:1vc将以v为根的子树中所有点颜色更改为c2v查询以v为根的子树中的节点有多少种不同的颜色$nle400000,1lecleft[iight]le60$题解没啥技术含量的题... 查看详情

codeforces620enewyeartree(代码片段)

挺好的一道题Descriptionlink给一棵树,每个点有颜色(c_i)为点权,需要实现以下两种操作:子树修改颜色(覆盖),查询子树颜色种类(nleq4 imes10^5,c_ileq60)Solution[Begin]首先看到子树和修改啥的,直接思考(dfs)序加线段树(从树剖学来... 查看详情

codeforces620dprofessorgukizandtwoarrays

1#include<bits/stdc++.h>23usingnamespacestd;45constintmaxn=2000+50;67constlonglonginf=1e18;89intn,m;1011longlongsuma,sumb;1213inta[maxn],b[maxn];1415longlongdbl_a[maxn],dbl_b[maxn];1617longlongs 查看详情

codeforces#620div2b(代码片段)

题目:Returningbacktoproblemsolving,Gildongisnowstudyingaboutpalindromes.Helearnedthata palindrome isastringthatisthesameasitsreverse.Forexample,strings"pop","noon","x",and"kkkkkk"arepalindromes,whilestrings"moon","tv",and"abab"arenot. Anemptystringisalsoapalindrome.Gildonglovesthisc... 查看详情

codeforces620c(代码片段)

题目链接:https://codeforces.com/problemset/problem/620/C题目分析       题意:给你一串珍珠,每个珍珠都有一个对应值,需要分割这n个珍珠(必须连续),使得每一串珍珠中含有对应值相同的两个珍珠,并让这... 查看详情

codeforces620fxorsonsegments回滚莫队+字典树||离心询问分治+可持久化字典树(代码片段)

XorsonSegments转换一下变成询问区间选两个数异或的最大值,要注意的是一个数作为左端点要-1,所以在回滚莫队的时候用两棵字典树维护。这个题居然n^2也能过。。。 其实用分治+可持久化字典树可以做到n*log(n)*log(n),懒得写了... 查看详情

pearlsinarowcodeforces620c水题

 题目:http://codeforces.com/problemset/problem/620/C文章末有一些测试数据仅供参考 题目大意:就是给你一个数字串,然后将分成几个部分,要求每个部分中必须有一对儿相等的数字,每个数字都属于某个部分,输出划分的部分... 查看详情

cf620e--newyeartree(线段树)

CodeForces-620E1.题意    对于一棵树进行以下两种操作:         1 vc 将根为v的子树全部染色为c      2v查询根为v的子树的颜色的个数2.思路     首先利用dfs时间序将树... 查看详情

数据结构专题

CodeForces628E CodeForces617ECodeForces618ECodeForces620ECodeForces611ECodeForces610DCodeForces609FCodeForces609ECodeForces605DCodeForces601DCodeForces597CCodeForces593DCodeForces589GCodeForces56 查看详情

codeforcesround#620(div.2)ddilworld定理

题:https://codeforces.com/contest/1304/problem/D题意:给定长度为n-1的只含’>‘和‘<’的字符串,让你构造出俩个排列,俩个排列相邻的数字之间要满足这个字符串,找出的俩个要是最小化最长上升子序列,和最大化最长... 查看详情

620.notboringmovies

Xcityopenedanewcinema,manypeoplewouldliketogotothiscinema.Thecinemaalsogivesoutaposterindicatingthemovies’ratingsanddescriptions.PleasewriteaSQLquerytooutputmovieswithanoddnumberedIDandadescriptiontha 查看详情

620.notboringmovies(代码片段)

Xcityopenedanewcinema,manypeoplewouldliketogotothiscinema.Thecinemaalsogivesoutaposterindicatingthemovies’ratingsanddescriptions.PleasewriteaSQLquerytooutputmovieswithanoddnumberedIDandadescriptiontha 查看详情

#leetcode#620.notboringmovies(代码片段)

https://leetcode.com/problems/not-boring-movies/ Xcityopenedanewcinema,manypeoplewouldliketogotothiscinema.Thecinemaalsogivesoutaposterindicatingthemovies’ratingsanddescriptions.Pleasewrite 查看详情

在 Quadro K620m 上运行 CUDA 程序

】在QuadroK620m上运行CUDA程序【英文标题】:RunningCUDAprogramsonQuadroK620m【发布时间】:2015-08-1116:59:24【问题描述】:我有配备QuadroK620mGPU的笔记本电脑。我正在尝试学习CUDA编程并从NVIDIA网站下载了网络安装程序。CUDASDK安装过程中,... 查看详情

e620.activatingakeystrokewhenanycomponentinthewindowhasfocus(代码片段)

Normally,akeystrokeregisteredtoacomponentisactivatedwhenthecomponenthasthefocus.ThistypeofactivationconditioniscalledWHEN_FOCUSED.Itispossibletospecifythatakeystrokebeactivatedifanycomponent(including 查看详情

设备列表显示 Chromecast 设备在 HTC Desire 620G 上处于“投射背景”中

】设备列表显示Chromecast设备在HTCDesire620G上处于“投射背景”中【英文标题】:DevicelistsaysChromecastdeviceisin"CastingBackdrop"onHTCDesire620G【发布时间】:2015-01-2908:07:14【问题描述】:我刚买了一部新的HTCDesire620G手机并尝试运行Go... 查看详情

DDK不识别DNDIS630,但它确实识别DNDIS620? (Windows NDIS)

】DDK不识别DNDIS630,但它确实识别DNDIS620?(WindowsNDIS)【英文标题】:DDKdoesn\'trecognizeDNDIS630,butitdoesrecognizeDNDIS620?(WindowsNDIS)【发布时间】:2022-01-0423:40:58【问题描述】:我正在尝试使用DDK构建环境构建NDIS驱动程序,版本是7600.16385... 查看详情