【CF1073B】Vasya and Books(模拟)
题意:给你一个栈里书的编号,每次能捞出栈顶的一本书,每次询问捞出某本编号的书需要捞几次
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(模拟)的更多相关文章
- Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟
A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...
- Codeforces Round #171 (Div. 2) B. Books (模拟队列)
题意:有一组数,问子数组和最大不超过\(t\)的最多元素个数. 题解:用数组模拟队列,不断的往里面放,队列中的元素之和大于\(t\),就不断地从队头弹出直到满足条件,维护一个最大值即可. 代码: in ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football(模拟)
简单题,却犯了两个错误导致WA了多次. 第一是程序容错性不好,没有考虑到输入数据中可能给实际已经罚下场的人再来牌,这种情况在system测试数据里是有的... 二是chronologically这个词 ...
- Gym-101915A Printing Books 模拟
题面 题意:给你N,X, X表示这本书从X开始编号,每个X是几位数,计数器就加几, 然后问你如果从X,开始编号,计数器为N的时候,翻了几页,不能刚好为N输出-1. (例如,5 99,答案为2,因为 ...
- 2018.12.21 浪在ACM 集训队第十次测试赛
浪在ACM 集训队第十次测试赛 A Diverse Substring B Vasya and Books C Birthday D LCM A 传送门 题解 B 传送门 题解: 这道题,就比较简单 ...
- Educational Codeforces Round 53 (Rated for Div. 2)
http://codeforces.com/contest/1073 A. Diverse Substring #include <bits/stdc++.h> using namespa ...
- Codeforces-Educational Codeforces Round 53题解
写之前,先发表下感慨:好久没写题解了,也许是因为自己越来越急利了,也可以说是因为越来越懒了. A. Diverse Substring 直接找一找有没有相邻的两个不同的字符即可. B. Vasya a ...
- CF1082解题报告
CF1082A Vasya and Book 模拟一下即可 \(Code\ Below:\) #include <bits/stdc++.h> using namespace std; c ...
- Educational Codeforces Round 53 Editorial
After I read the solution to the problem, I found that my solution was simply unsightly. Solved 4 ou ...
随机推荐
- 23.VUE学习之-列表的排序sort
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue之神奇的动态按钮
今天我们将利用vue的条件指令来完成一个简易的动态变色功能按钮 首先我们还是要对vue进行配置,在上篇随笔中有相关下载教学. 然后我们要在html页面上搭建三个简易的按钮,颜色分别为紫,绿和蓝(颜色随 ...
- 异步消息处理机制,UI更新
UI只能在主线程中完成更新,在子线程中更新UI报错如下 Only the original thread that created a view hierarchy can touch its vie ...
- postgreysql
基础 syntax * \help 生成所有的pg命令 * abort 终止事务/work * alter aggregate 修改聚合函数的定义 ALTER AGGREGATE name ( typ ...
- D3DXCreateTextureFromFile
HRESULT D3DXCreateTextureFromFile( __in LPDIRECT3DDEVICE9 pDevice, __in LPCTSTR pSrcFile, __out LPDI ...
- mysql之处理金钱小数点后的多余0
问题产生原因:我们在做基金项目 产生大量的金钱 在GP首页展示首页信息的时候要求去除多余的0 由于我们在数据库设计的时候查询返回数据 例如18.100000 这种形式 而我们需要将多余的0 ...
- win8 远程桌面时提示凭证不工作问题的终极解决办法
环境说明 远程办公电脑(放置于公司.自用办公电脑.win8系统) 远程连接客户机(放置于家中.家庭日常所用.win8系统) 故障现象 最近在使用远程桌面连接公司的办公电脑时,突然发现win8系统总是无 ...
- Eclipse启动错误:A Java Runtime Environment(JRE) or Java Development Kit(JDK) must be available……
确保Jdk,Jre都安装完成并且环境变量配置无误的情况下,自动Ecplise报错如下: A Java Runtime Environment (JRE) or Java Development Kit ...
- python - 接口自动化测试 - RunTest - 测试用例加载执行/测试报告生成
# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: run_test.py @ide: PyCharm Com ...
- Halcon18 windows 下载
Halcon18 windows 下载地址:http://www.211xun.com/download_page_13.html HALCON 18 是一套机器视觉图像处理库,由一千多个算子以及底层 ...