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 ...
随机推荐
- clion windows 开发配置
1.下载clion 并且安装. 地址 : http://download-cf.jetbrains.com/cpp/clion-1.0.1.exe 2.安装cygwin 地址: https://cy ...
- Asp.net 同时下载多个文件
整理自网络 下载思路是首先把多个文件进行压缩,然后再下载压缩成的压缩包 引用文件dll:ICSharpCode.SharpZipLib.dll 1. 合成下载文件夹 Protected Sub btn ...
- 3244: [Noi2013]树的计数 - BZOJ
Description 我们知道一棵有根树可以进行深度优先遍历(DFS)以及广度优先遍历(BFS)来生成这棵树的DFS序以及BFS序.两棵不同的树的DFS序有可能相同,并且它们的BFS序也有可能相同, ...
- PHP中应用Service Locator服务定位及单例模式
单例模式将一个对象实例化后,放在静态变量中,供程序调用. 服务定位(ServiceLocator)就是对象工场Factory,调用者对象直接调用Service Locator,与被调用对象减轻了依赖关 ...
- git Clone SSL certificate problem: self signed certificate
自己的git服务器遇到证书是自签的,git验证后会拒绝,此时,采用如下命令临时禁用就好 git -c http.sslVerify=false clone https://domain.com/pat ...
- centos6.5安装vmware-tools
一.问题描述 为什么使用vmware-tools:传文件方便,可以从主机中直接拖拽文件到centos中(但实际上我们可以用:WinSCP):鼠标切换方便,鼠标指到什么地方,表名当前正在操作哪个环境(但 ...
- [转载]C# Double toString保留小数点方法
有时候double型数据需要toString(),但又想保留小数,当值为整数,比如3.00时tostring后会变为”3″,具体说明见下: 1 string str0 = i.ToString(&qu ...
- 谁会是 Zabbix 和 Nagios 的继任者?
[编者按]本文根据 Dataloop.IO 的创始人兼 CEO David Gildeh 对监控工具市场的现状分析以及对未来发展趋势的展望,展开拓展讨论. 为什么监控还是一塌糊涂? 为了调研市场,从而 ...
- Javascript 中判断是谷歌浏览器和IE浏览器的方法
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- Selenium--cssselector
CSS(即层叠样式表Cascading Stylesheet) Selector来定位(locate)页面上的元素(Elements).Selenium官网的Document里极力推荐使用CS ...