CF757G.Can Bash Save the Day?

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Whoa! You did a great job helping Team Rocket who managed to capture all the Pokemons sent by Bash. Meowth, part of Team Rocket, having already mastered the human language, now wants to become a master in programming as well. He agrees to free the Pokemons if Bash can answer his questions.

Initially, Meowth gives Bash a weighted tree containing nn nodes and a sequence a1,a2...,ana_{1},a_{2}...,a_{n} which is a permutation of 1,2,...,n1,2,...,n . Now, Mewoth makes qq queries of one of the following forms:

  • 1 l r v: meaning Bash should report , where dist(a,b)dist(a,b) is the length of the shortest path from node aa to node bb in the given tree.
  • 2 x: meaning Bash should swap axa_{x} and ax+1a_{x+1} in the given sequence. This new sequence is used for later queries.

Help Bash to answer the questions!

输入格式

The first line contains two integers nn and qq ( 1<=n<=21051<=n<=2·10^{5} , 1<=q<=21051<=q<=2·10^{5} ) — the number of nodes in the tree and the number of queries, respectively.

The next line contains nn space-separated integers — the sequence a1,a2,...,ana_{1},a_{2},...,a_{n} which is a permutation of 1,2,...,n1,2,...,n .

Each of the next n1n-1 lines contain three space-separated integers uu , vv , and ww denoting that there exists an undirected edge between node uu and node vv of weight ww , ( 1<=u,v<=n1<=u,v<=n , uvu≠v , 1<=w<=1061<=w<=10^{6} ). It is guaranteed that the given graph is a tree.

Each query consists of two lines. First line contains single integer tt , indicating the type of the query. Next line contains the description of the query:

  • t = 1: Second line contains three integers aa , bb and cc ( 1<=a,b,c<2^{30} ) using which ll , rr and vv can be generated using the formula given below:
    • ,
    • ,
    • .
  • t = 2: Second line contains single integer aa ( 1<=a<2^{30} ) using which xx can be generated using the formula given below:
    • .

The ansians_{i} is the answer for the ii -th query, assume that ans0=0ans_{0}=0 . If the ii -th query is of type 2 then ansians_{i} = ansi1ans_{i-1} . It is guaranteed that:

  • for each query of type 1: 1<=l<=r<=n1<=l<=r<=n , 1<=v<=n1<=v<=n ,
  • for each query of type 2: 1<=x<=n11<=x<=n-1 .

The operation means bitwise exclusive OR.

输出格式

For each query of type 11 , output a single integer in a separate line, denoting the answer to the query.

输入输出样例

  • 输入#1

    5 5
    4 5 1 3 2
    4 2 4
    1 3 9
    4 1 4
    4 5 2
    1
    1 5 4
    1
    22 20 20
    2
    38
    2
    39
    1
    36 38 38
    

    输出#1

    23
    37
    28
    

说明/提示

In the sample, the actual queries are the following:

  • 1 1 5 4
  • 1 1 3 3
  • 2 3
  • 2 2
  • 1 1 3 3
首页