#P3767. 魔法

    ID: 2709 远端评测题 1500ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>搜索线段树并查集洛谷原创分治洛谷月赛

魔法

Description

The magic array consists of NN nodes.

Each node can have one of five attributes: metal, wood, water, fire, earth. They satisfy the generate/overcome relationships.

At the beginning, there are no spells in the magic array.

Each time, Xiao Y will add a spell that requires the attributes of two nodes to satisfy a generate/overcome relationship. Then you need to answer whether there exists an assignment of an attribute to each node that satisfies all the requirements.

To adjust the array, Xiao Y sometimes needs to delete a previously written spell.

Xiao Y thinks this problem is too easy, so he uses the ability to change the timeline, making each operation be applied on the magic array resulting right after some previous operation.

Input Format

The first line contains two positive integers N,MN, M, the number of nodes and the number of operations.

Then follow MM lines, each containing four numbers describing one operation.

The first number kk means this operation is applied to the magic array obtained right after the kk-th operation. If k=0k = 0, it is applied to the initial magic array.

The second number tt indicates the operation type.

  • t=1t = 1: then input u,vu, v, meaning to add a spell requiring uu generates vv.
  • t=2t = 2: then input u,vu, v, meaning to add a spell requiring uu overcomes vv.
  • t=3t = 3: then input xx, meaning to delete the spell added by the xx-th operation.

Output Format

For each operation, if after the operation there exists an assignment of attributes to all nodes that satisfies all the requirements, output excited; otherwise, output naive.

3 6  
0 1 1 2  
1 1 2 3  
2 2 1 3  
2 1 3 1  
2 3 1  
5 1 3 1
excited  
excited  
excited  
naive  
excited  
excited  

Hint

For 30%30\% of the testdata, N,M100N, M \leq 100.

For another 30%30\% of the testdata, ki=i1k_i = i - 1.

For 100%100\% of the testdata, N,M100000N, M \leq 100000, 0ki<i0 \leq k_i < i, uiviu_i \neq v_i, 1ui,viN1 \leq u_i, v_i \leq N, and all delete operations are guaranteed to be valid.

Translated by ChatGPT 5