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 ...
随机推荐
- 使用ASP.NET注册工具aspnet_regiis.exe注册IIS
该工具的名称为aspnet_regiis.exe,在32位机上,该工具存在于C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727,在64位机中“Framework ...
- 3144:[HNOI2013]切糕 - BZOJ
题目描述 Description 经过千辛万苦小 A 得到了一块切糕,切糕的形状是长方体,小 A 打算拦腰将切糕切成两半分给小 B.出于美观考虑,小 A 希望切面能尽量光滑且和谐.于是她找到你,希望你 ...
- angular入门系列教程3
主题: 本篇主要目的就是继续完善home页,增加tab导航的三个页index index1 index2 效果图: 细节: 初始化的JS就是咱们的home.js,仔细来看. angular的route ...
- HDU 4811 Ball 贪心
题目链接: 题目 Ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 问题描述 ...
- HDU 5629 Clarke and tree dp+prufer序列
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=562 题意: 求给每个节点的度数允许的最大值,让你求k个节点能组成的不同的生成树个数. 题解: 对于n ...
- jquery easyui datagrid 获取选中多行
var rows = $('#dataTable').datagri('getSelections');
- 已收录的帝国cms文章被误删除了怎么办?
我们一直提倡网站要经常备份,但是有时也会遗忘,一不小心被谁删除了那就欲哭无泪了.就像ytkah刚弄了一个站,开了个权限比较高的后台帐号给别人用,居然把两三个栏目都删除了,想发狂啊.刚好又有段时间没备份 ...
- PHPStorm 3.0 与服务器端代码同步配置
首先打开PhpStrom->Toolbar->Settings(工具栏的倒数第三行) 进入Settings后的界面如下 单击进入左边Deployment目录,在右边配置信息里面进行配置 填 ...
- hdu 4417 Super Mario 离线线段树
思路:将点按值从小到大排序,询问按h从小到大排序. 在建立线段树,按h的大小更新树并得到该次查询的结果! 代码如下: #include<iostream> #include<stdi ...
- hdu 4282 A very hard mathematic problem
由于k的范围是0-2^31,而且x,y,z都是正整数,由题易知道2<=z<31,1<=x<y;所以直接枚举就好了!!! #include<iostream> #in ...