URAL1992-CVS
2017-04-11 20:02
302 查看
1992. CVS
Time limit: 1.0 secondMemory limit: 64 MB
Yoda: Visit I will the cloners on Kamino... And see this army they have created for the Republic.
Cloners from the Kamino planet breed some of the finest clones. Such good results are due to the careful management over the clones’ evolution. The Kaminuans are now busy working out a new study technology
that lets increase the clones’ effectiveness. The cloners have come up with a new control system CVS (Clone Version System) that makes managing the progress of experiments easier. The system is quite simple to use.
The Kaminuans have some set of educational programs at their disposal. A clone’s effectiveness depends on which programs and in which order he has learned. The Kaminuans can teach any clone a program
as long as this clone hasn’t learned it already.
To make the experiments even easier to conduct, the Kaminuans enabled canceling the changes made by the last program the clone has learned. In this case, the clone’s knowledge returns to the level when
the program hasn’t yet been studied. Then this clone can study this program in the future. You can cancel programs at any time unless the clone is at the basic knowledge level.
Besides the ‘roll back’ function, a clone can ‘re-learn’ a program. If one cancels some program by mistake, he can cancel the cancellation. The CVS keeps record of each clone’s canceled programs. After
a program is canceled, the CVS adds another record. After a clone re-learn a program, the record is deleted. If a clone learn (not relearn) a program, all cancellation record history of this clone is deleted. You can use the re-learn function as long as the
record history for this clone contains any records.
Finally, the system has a ‘clone’ option. If a Kaminuan likes the current variant of a clone, he can clone the clone, that is, create a new clone with the same sequence of taught programs and cancellation
history.
Initially the Kaminuans have a single clone with basic knowledge. Help them analyze the progress of the experiments.
Input
The first line of the input contains numbers n — the number of queries — and m — the number of educational programs (1 ≤ n, m ≤ 5·105).Each of the following n lines has one of the formats given below.
learn ci pi. Teach clone ci program pi (1
≤ pi ≤ m).
rollback ci. Cancel the last learned program for clone ci.
relearn ci. Apply ‘re-learn’ function to clone ci.
clone ci. Clone the clone ci.
check ci. Display the last program clone ci has learned and
knows at the moment.
It is guaranteed that rollback won’t be applied to the clone that is at the basic knowledge level. learn is always applied with the program a clone doesn’t already know. relearn is only applied if the cancellation history of a clone
is not empty. It is also guaranteed that only the clones that already exist can occur in the queries. The numbers are assigned to the clones in the order the clones appear. The Kaminuans started their experiments from clone number one.
Output
For each check ci query display the result on a single line. If some clone has only basic knowledge,print basic, otherwise print the number of the last learned program.
Sample
input | output |
---|---|
9 10 learn 1 5 learn 1 7 rollback 1 check 1 clone 1 relearn 2 check 2 rollback 1 check 1 | 5 7 basic |
题意:有五个操作,learn x y,让x学习y知识;rollback x,让x遗忘最后一个学习的知识;check x,问x最后学习的是什么,relearn x,让x学习一个最后一个遗忘的知识;clone x,复制一个x
解题思路:数组模拟链表
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <climits> #include <functional> #include <vector> #include <map> #include <set> using namespace std; #define LL long long int n,m,x,y; int s[1000006],ss[1000006],e[1000006],nt[1000006]; char ch[100]; int main() { while(~scanf("%d%d",&n,&m)) { s[1]=ss[1]=-1; int cnt=0,cnt1=1; for(int i=0;i<n;i++) { scanf("%s",ch); if(!strcmp(ch,"learn")) { scanf("%d%d",&x,&y); nt[cnt]=s[x],s[x]=cnt,e[cnt++]=y;ss[x]=-1; } else if(!strcmp(ch,"clone")) { scanf("%d",&x); cnt1++; s[cnt1]=s[x];ss[cnt1]=ss[x]; } else if(!strcmp(ch,"rollback")) { scanf("%d",&x); y=e[s[x]]; s[x]=nt[s[x]]; nt[cnt]=ss[x],ss[x]=cnt,e[cnt++]=y; } else if(!strcmp(ch,"relearn")) { scanf("%d",&x); y=e[ss[x]]; ss[x]=nt[ss[x]]; nt[cnt]=s[x],s[x]=cnt,e[cnt++]=y; } else { scanf("%d",&x); if(s[x]==-1) printf("basic\n"); else printf("%d\n",e[s[x]]); } } } return 0; }
相关文章推荐
- URAL 1992 CVS 链表
- URAL 1992 CVS
- CVS (URAL 1992 可持久化的链表)
- URAL 1992 CVS
- URAL 1992 CVS 链表
- URAL 1992
- URAL 1992
- ural 1207 Median on the Plane
- ural 1090 In the Army Now
- ural 1146. Maximum Sum
- Ural 1136 Parliament / 后序遍历二叉树
- URAL 1260 Nudnik Photographer(递推)
- Ural 1068 - Sum
- URAL 1549 Another Japanese Puzzle
- URAL - 1907 Coffee and Buns 容斥原理+数论
- window的客户端连接linux中的cvs服务器出现问题
- CVS 提示错误的意思
- 删除SVN、CVS版本控制信息
- ural1147(Shaping Regions)矩形切割
- 第十五章 高级特性-开放源码:BIRT报表CVS构建