Sum insertion P83997


Statement
 

pdf   zip

Please implement an efficient data structure to support just one operation. Let x1,,xnx_1, \dots, x_n be the current elements (natural numbers) in the data structure, all different and in increasing order. Given three parameters yy, ii, and jj, you must insert z=(y+ikjxk)mod109z = (y + \sum_{i \le k \le j} x_k) \bmod 10^9 into your data structure. Assume that you start with just one element, with value 0.

Input

Input begins consists of several cases. Each case starts with the number of insertions mm. Follow mm triples yy ii jj. Assume 1m1051 \le m \le 10^5, 0y<1090 \le y < 10^9, and 1ijn1 \le i \le j \le n. The end of input is indicated with a special case with m=0m = 0.

Output

For every operation, if zz is a new value, insert zz and print I zz. Otherwise, do not insert zz and print R zz. Print a line with 10 dashes at the end of each case.

Public test cases
  • Input

    4
    5 1 1
    3 1 1
    2 1 2
    3 2 3
    
    5
    0 1 1
    999999999 1 1
    1 2 2
    999999999 1 2
    999999999 1 3
    
    0
    

    Output

    I 5
    I 3
    R 5
    I 11
    ----------
    R 0
    I 999999999
    R 0
    I 999999998
    I 999999996
    ----------
    
  • Information
    Author
    Pol Mauri
    Language
    English
    Official solutions
    C++
    User solutions
    C C++