F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Harry Potter and Cyber Sequence Generator

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 623    Accepted Submission(s): 224


Problem Description
After Voldemort and the Death Eater were wiped out by Harry Potter and his friends, Harry becomes the glory of the Wizarding World, magician treat him as model, hero, king´ and much more than that.
   Recently Harry Potter and his friends have been researching a kind of toy from the Muggle World, with the name Cyber Sequence Generator, wondering if after manipulated in some certain way, it can be useful and powerful for magicians.
  This kind of generator has two magic containers C1 and C2, if we put a magic element in C1, after its magic is all over, the result magic element can be taken from C2. Because we Muggles(I¨m sorry if you are not a muggle, you can ask me for magic student version of this problem statement even you are competing and can¨t use the Internet) do not know magic languages, let¨s rearrange the words to describe how the generator works.
  The generator¨s work can be split into simple works. Each work is like:

SET|ADD C1|C2, C1|C2|IntegerNumber
MUL C1|C2, IntegerNumber

By ^SET a,b ^, we have the value of the element in container a changed to b
By ^ADD a,b ^, we have the value of the element in container a added by b
By ^MUL a,b ^, we have the value of the element in container a multiplied by b
After each of the operations, the value in b will not change.
  Here C1, C2 denotes actually the value of magic element.
C2¨s initial value is 0.
  All works are done in the order in input.
  
  Harry always has a magic element V at first, and can use the generator arbitary times, and wonders if so, what is the value of the result element.
 

Input
  One line T, the number of test cases.
  For each test case, first line contains one integer V. Then a few lines describe the Cyber Sequence Generator, ended by ^END ̄.
  Then an integer Q, the number of Queries.
  Q number following describe how many times Harry use the generator, for each query N , we have the initial value is V, and C2¨s initial value is 0.
  The instruction is like "SET_a,_b".(underscore '_' is just used to demonstrate blank char)
 

Output
  For each test case, first output a line "Case num:", while num is the case number, based on 1. There is one space between 'Case' and 'num' and no more blanks in the same line.
  
For each query, output a line of the value of the result magic element, modulo prime p = 109+7(i.e 1 000 000 007).
  
Constraints
1<=T<=10
1<=N<=10100
1<=Q<=100
  One generator has no more than 100 instructions.
  All integer constants in SET/ADD/MUL instruction will fit 32-bit integer type.
 

Sample Input
2 1 ADD C1, 1 SET C2, C1 END 5 1 2 3 4 5 1 ADD C1, C1 SET C2, 1 ADD C2, C1 SET C1, C2 END 5 1 2 3 4 5
 

Sample Output
Case 1: 2 3 4 5 6 Case 2: 3 7 15 31 63
 

Author
WHU
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-12 07:45:01, Gzip enabled