URAL 1992
CVS
Description
Input
- 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
Sample Input
input | output |
---|---|
9 10 |
5 |
#include <cstdio>
#include <iostream>
#define N 500005
using namespace std;
int now[N],tot_ro,c,p;
int stack[N],pre[N],tot;
int stack_ne[N],now_ne[N],next[N],tot_ne;
char order[];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
tot=tot_ne=;
tot_ro=;
now[]=now_ne[]=;
for(int i=; i<n; i++){
scanf("%s",order);
switch (order[]) {
case 'n'://learn
scanf("%d%d",&c,&p);
stack[++tot]=p;
pre[tot]=now[c];
now[c]=tot;
now_ne[c]=;
break;
case 'b'://rollback
scanf("%d",&c);
if(now[c]!=){
stack_ne[++tot_ne]=stack[now[c]];
next[tot_ne]=now_ne[c];
now_ne[c]=tot_ne;
now[c]=pre[now[c]];
}
break;
case 'a'://relearn
scanf("%d",&c);
if(now_ne[c]!=){
stack[++tot]=stack_ne[now_ne[c]];
pre[tot]=now[c];
now[c]=tot;
now_ne[c]=next[now_ne[c]];
}
break;
case 'e'://clone
scanf("%d",&c);
if(c<=tot_ro){
now[++tot_ro]=now[c];
now_ne[tot_ro]=now_ne[c];
}
break;
case 'k'://check
scanf("%d",&c);
if(now[c]==)
printf("basic\n");
else
printf("%d\n",stack[now[c]]);
break;
}
}
}
return ;
}
URAL 1992的更多相关文章
- URAL 1992 CVS
CVS 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1992 Description Yoda: Visit I will the c ...
- URAL 1992 CVS 可持久化链栈
http://www.cnblogs.com/tedzhao/archive/2008/11/12/1332112.html 看这篇的链表部分的介绍应该就能理解“可持久化”了 动态分配内存的会T,只能 ...
- URAL 1992 CVS 链表
不更改链表结构,只是添加节点,没有删除节点.通过记录和更改标记来模拟题意的插入和删除,复制 指针模拟链表: 预开指针,存在M[]中,可以提高效率 #include<functional> ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
随机推荐
- python学习小结2:if和while控制语句
if语句 if语句中,代码块是按缩进的空格数量来判断的,也就是说空格数量一致的相邻行会被当作一个代码块,当if的条件成立的时候它就会得到执行. x = 100 if x > 50: print ...
- ios map 显示用户位置
昨天遇到个奇怪的问题,用户的位置在地图中死活不显示,showUserLocation也设置了,最后发现是因为实现了 mapView protocol中的一个方法: -(MKAnnotationView ...
- C#快速排序算法基础入门篇
相信算法对于许多开发人员来说都是一大难点,之所以难,就像设计模式一样,许多人在阅读之后,没有很好地理解,也不愿意动手上机操作,只停留在理论的学习上面,随着时间推移就慢慢淡忘. 有些东西,你可以发明创造 ...
- 【POJ】【2068】Nim
博弈论/DP 这是Nim?这不是巴什博奕的变形吗…… 我也不会捉啊,不过一看最多只有20个人,每人最多拿16个石子,总共只有8196-1个石子,范围好像挺小的,嗯目测暴力可做. so,记忆化搜索直接水 ...
- struct2访问或添加request/session/application
访问或添加request/session/application 1 通过ActionContext //这样放置 public String execute() { ActionConte ...
- java 中 String 类的几个问题
首先,我们要搞清楚,在java中,引用和基本数据类型是存储在栈中的.而对象是存储在堆中的. 只有一个例外,就是String对象. 例如: String str1="test"; S ...
- linux源码阅读笔记 void 指针
void 指针的步长为1,而其他类型的指针的步长与其所定义的数据结构有关. example: 1 #include<stdio.h> 2 main() 3 { 4 int a[10]; 5 ...
- SDUT1574组合数的计算(组合数)
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1574 这个题,比较奇怪,是用递推去做的,我试了 ...
- mac 安装mysql 报错“ERROR 2002 (HY000): Can not connect to local MySQL server through socket '/tmp/mysql.sock' (2)” 解决办法
首先安装 homebrew 再 brew install mysql 之后连接 mysql 无论是登录还是修改初始密码都会报如下的错误 ERROR 2002 (HY000): Can not conn ...
- XML DOS 攻击
内容来自此文:http://msdn.microsoft.com/en-us/magazine/ee335713.aspx DoS(Denial of service:拒绝服务)攻击由来已久(1992 ...