题意:给你一个栈里书的编号,每次能捞出栈顶的一本书,每次询问捞出某本编号的书需要捞几次

n<=2e5

思路:

 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 210000
#define MOD 1000000007
#define eps 1e-8
#define pi acos(-1)
#define oo 1e18 int a[N],b[N],c[N],inq[N],stk[N]; int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) scanf("%d",&b[i]);
int top=n;
for(int i=;i<=n;i++)
{
stk[i]=a[n-i+];
inq[i]=;
}
for(int i=;i<=n;i++)
{
c[i]=;
while(inq[b[i]]&&stk[top]!=b[i])
{
c[i]++;
inq[stk[top--]]=;
}
if(inq[b[i]]){c[i]++; inq[stk[top--]]=;}
}
for(int i=;i<=n-;i++) printf("%d ",c[i]);
printf("%d\n",c[n]);
return ;
}

【CF1073B】Vasya and Books(模拟)的更多相关文章

  1. Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟

    A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...

  2. Codeforces Round #171 (Div. 2) B. Books (模拟队列)

    题意:有一组数,问子数组和最大不超过\(t\)的最多元素个数. 题解:用数组模拟队列,不断的往里面放,队列中的元素之和大于\(t\),就不断地从队头弹出直到满足条件,维护一个最大值即可. 代码: in ...

  3. Codeforces Round #281 (Div. 2) A. Vasya and Football(模拟)

    简单题,却犯了两个错误导致WA了多次. 第一是程序容错性不好,没有考虑到输入数据中可能给实际已经罚下场的人再来牌,这种情况在system测试数据里是有的... 二是chronologically这个词 ...

  4. Gym-101915A Printing Books 模拟

    题面 题意:给你N,X,   X表示这本书从X开始编号,每个X是几位数,计数器就加几, 然后问你如果从X,开始编号,计数器为N的时候,翻了几页,不能刚好为N输出-1. (例如,5 99,答案为2,因为 ...

  5. 2018.12.21 浪在ACM 集训队第十次测试赛

     浪在ACM 集训队第十次测试赛 A Diverse Substring B Vasya and Books C Birthday D LCM A 传送门 题解 B 传送门 题解: 这道题,就比较简单 ...

  6. Educational Codeforces Round 53 (Rated for Div. 2)

    http://codeforces.com/contest/1073 A. Diverse Substring #include <bits/stdc++.h> using namespa ...

  7. Codeforces-Educational Codeforces Round 53题解

    写之前,先发表下感慨:好久没写题解了,也许是因为自己越来越急利了,也可以说是因为越来越懒了. A. Diverse Substring 直接找一找有没有相邻的两个不同的字符即可. B. Vasya a ...

  8. CF1082解题报告

    CF1082A Vasya and Book 模拟一下即可 \(Code\ Below:\) #include <bits/stdc++.h> using namespace std; c ...

  9. Educational Codeforces Round 53 Editorial

    After I read the solution to the problem, I found that my solution was simply unsightly. Solved 4 ou ...

随机推荐

  1. Nginx+proxy_cache图片缓存

    搭建图片缓存机制的原理在于减少数据库的负担并加快静态资源的响应. 步骤: 1. vim /usr/local/nginx/conf/nginx.conf 2. http{     ...     .. ...

  2. linux正则表达式企业级深度实践案例1

    linux正则表达式结合三剑客企业级实践: 1.取系统ip [root@redhat~]#  ifconfig  eth0 解答: 替换命令: sed  's#支持正则位置##g'  file 先取第 ...

  3. L2TP用户添加和删除、搜索脚本

    #!/bin/bash #author Template . /etc/init.d/functions DATE_TIME=$(date +%F-%T) FILE_PATH='/etc/ppp/ch ...

  4. ATM-core-src

    from interface import bank, shopping, userfrom lib import common user_data = { 'name': None} def log ...

  5. 洛谷 P2279 [HNOI2003]消防局的设立

    题目描述 2020年,人类在火星上建立了一个庞大的基地群,总共有n个基地.起初为了节约材料,人类只修建了n-1条道路来连接这些基地,并且每两个基地都能够通过道路到达,所以所有的基地形成了一个巨大的树状 ...

  6. 基于django的个人博客网站建立(三)

    基于django的个人博客网站建立(三) 前言 网站效果可点击这里访问 今天主要完成的是文章在页面的显示以及评论,留言 具体内容 首先我希望主页面是显示我的所有文章,于是在主页面的视图函数中返回了所有 ...

  7. python3下最全的wordcloud用法,附源代码及相关文件

    一.wordcloud是什么 词云,在一段文本中提取关键词进行扁平化的展示,更能吸引目标客户的眼球. 市面上有很多在线生成词云的工具,本文以Python中的第三方库wordcloud为例讲解如何自动生 ...

  8. C++ 虚函数实例

    #include <iostream> using namespace std; //线 class Line { public: Line(float len); ; ; protect ...

  9. 2017 ACM-ICPC EC-Final ShangHai(思维乱搞赛)

    感觉全是思维乱搞题. Gym - 101775J Straight Master 给你n种扑克,你每次可以出连续的3 ~ 5 张,问你能否出完. Sample Input 2 13 1 2 2 1 0 ...

  10. JVM垃圾回收原理

    原文地址:http://chenchendefeng.iteye.com/blog/455883 一.相关概念 基本回收算法 1. 引用计数(Reference Counting) 比较古老的回收算法 ...