Levve Loves Segment Trees

View as PDF

Submit solution

Points: 15
Time limit: 1.0s
Java 2.0s
Python 4.0s
Memory limit: 1G

Author:
Problem type

Levve loves segment trees, so he has given you the following task:

You are given an array of N zeroes and Q operations of the following forms:

  • C x v: Change the element's value at index x to v.
  • S l r: Output the sum of all elements between indices l and r, inclusive.
  • M l r: Output the maximum of all elements between indices l and r, inclusive.

Levve doesn't like cheesing, so you will not be given li, ri, xi or vi directly. Instead of li, you will be given li, which can be decrypted using the formula li=lilastAns where lastAns represents the output to the previous S or M query, and represents the bitwise xor operation. If there is no previous output, lastAns=0.

Similarly:

  • ri=rilastAns
  • xi=xilastAns
  • vi=vilastAns

Constraints

1N1018

1Q4×105

1xN

0v109

1lrN

Input Specification

The first line contains two space-separated integers, N and Q.

The following Q lines each contain a query of one of the previously described forms.

Output Specification

For each S or M query, output its result on a new line.

Sample Input

Copy
10 5
C 2 1
C 7 3
S 1 5
C 2 9
M 2 8

Sample Input (Unencrypted)

Copy
10 5
C 2 1
C 7 3
S 1 5
C 3 8
M 3 9

Sample Output

Copy
1
8

Comments


  • 0
    maxcruickshanks  commented on Aug. 8, 2022, 4:49 p.m.

    Since the original data were weak, an additional test case was added, and all submissions were rejudged.