Retroactive Integers
Practice
0 (0 votes)
Approved
Data structures
Matrix
Medium
Segment trees
Problem
83% Success 176 Attempts 50 Points 7s Time Limit 1024MB Memory 1024 KB Max Code

You're maintaining 20 variables: \(a, b, c, \dots, r, s, t\). At any moment of time value of any variable is integer between 0 and \(1,000,000,006\), inclusive. All arithmetic operations with variables are modulo \(1,000,000,007\). Initially (at moment 0) all variables are set to 0. At some moments of time, you get queries. Queries have 5 different types:

  1. \(\textrm{"? x"}\) print value of variable x.
  2. \(\textrm{"= x y"}\) write value of variable y to variable x.
  3. \(\textrm{"! x c"}\) set variable x to c.
  4. \(\textrm{"+ x c"}\) add c to variable x.
  5. \(\textrm{"* x c"}\) multiply variable x by c.

Also with each query you are given a positive integer --- time when you need to apply this query to variables. Times can go in arbitrary order. See sample for further clarification.

Input Format:
First line contain one integer q --- number of queries.
Next q lines contains queries. i-th query starts with integer \(t_i\) --- time this query should be made at.
Then one of 5 query goes in format, described in the statement.

Output Format:
For each query of the first time print the corresponding value.

Constraints:
\(1 \leqslant q \leqslant 100,000.\)
\(1 \leqslant t_i \leqslant 1,000,000,000.\)
All \(t_i\) are distinct.
In all queries, \(x, y \in \{a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t \}.\)
Also in all queries \(0 \leqslant c \leqslant 1,000,000,006.\)

Scoring:
20 points
Additionally \(q \leqslant 5,000\).
20 points
Additionally, in all queries, \(x = y = a\).
Also queries only of types \(\textrm{*, +, ?}\) are present.
20 points
Additionally, in all queries \(x, y \in \{a, b, c, d, e\}\).
40 points
No additional constraints.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
8 votes
Tags:
MediumSegment Trees
Points:50
Tags:
Data StructuresMediumSegment Trees
Points:50
1 votes
Tags:
ApprovedData StructuresMediumSegment Trees