[CF1066C]Books Queries

题目大意:维护一个数列,要求在左边插入一个数,在右边插入一个数,查询一个数的排名

题解:可以双指针,开个数组存每个数的位置

卡点:

C++ Code:

#include <cstdio>
#define maxn 200010
int n, l, r = 1;
int ret[maxn];
inline int min(int a, int b) {return a < b ? a : b;}
int main() {
	scanf("%d", &n);
	while (n --> 0) {
		char ch;
		int x;
		scanf("%1s%d", &ch, &x);
		switch (ch) {
			case ‘L‘:
				ret[x] = l--;
				break;
			case ‘R‘:
				ret[x] = r++;
				break;
			case ‘?‘:
				printf("%d\n", min(ret[x] - l, r - ret[x]) - 1);
		}
	}
	return 0;
}

  

原文地址:https://www.cnblogs.com/Memory-of-winter/p/9909259.html

时间: 2024-10-03 09:11:46

[CF1066C]Books Queries的相关文章

Books Queries (codeforces 1066C)

模拟题 开一个容器进行模拟即可,注意容器设置初始大小不然容易re.设置两个指针l,r.把容器当作桶,每一个桶都有一个编号表示位置,左边进入那么就是编号为l,右边一样.然后l--或者r++,l=r=0的初始值,第一个元素为0,然后同时l--,r++ 代码(cf上的题解) #include <bits/stdc++.h> using namespace std; main() { int n; cin>>n; deque<int> vec(300000); int l=0;

CF1066 A &amp; B &amp; C

A 题目链接CF1066 A Vova and Train 思路: 类似前缀和暴力搞一下 code: #include <bits/stdc++.h> using namespace std; int T, L, V, l, r; template <typename T> inline void read(T &t) { ; } int main() { scanf("%d", &T); while(T--) { int ans = 0; sc

Codeforces Round #515 (Div. 3)

Codeforces Round #515 (Div. 3) 1 #include<bits/stdc++.h> 2 #include<iostream> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<cstring> 6 #include<cmath> 7 #include<algorithm> 8 #include<queue> 9 #include&l

714 - Copying Books——[贪心、二分查找]

Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had been given a book and after several months he finished its copy. One of the most fa

django 运行python manage.py sqlall books 时报错 app has migration

出现这个问题的原因是版本之前的不兼容,我用的django版本是1.8.6 而 这条python manage.py sqlall books 是基于django1.0版本的. 在django1.8.6版本中生成一个表的语句是    $ python manage.py makemigrations books $ python manage.py sqlmigrate books 0001 django book2 是一本不错的教程,但是就是版本太老了,可以通过看book2对django有一个比

Red style books store OpenCart 主题模板 ABC-0117

Red style books store OpenCart 主题模板 ABC-0117 RED STYLE BOOKS STORE OPENCART 主题模板 ABC-0117 Designed with luxurious colorsSuitable for shop selling: Books , templates, Card, picture, Art, Photography..Designed by CSS, HTMLSupports multiple languages, m

HDU4027 Can you answer these queries 线段树区间求和+剪枝

给了你n,然后n个数字在一个数组中,接下来m个询问,每个询问三个数字 t,x,y,若t==0,那么修改区间[x,y]的每一个值,变为原来每个位置上的数 开根号取整,若t==1,那么对区间[x,y]求和 由于n,m,很大,所以树状数组铁定超时,若直接用线段树来做区间修改,那么也是超时,这类题目没别的方法了,静心剪枝,发现题目给的数据范围为2^63,有没有发现,2^63开根号 绝对不需要开10次,就能到1,到1以后就不需要再开了,意思就是若有某个区间[x,y]每一个点的值都为1时,这一段区间事实上是

[CodeChef - GERALD07 ] Chef and Graph Queries

Read problems statements in Mandarin Chineseand Russian. Problem Statement Chef has a undirected graph G. This graph consists of N vertices and M edges. Each vertex of the graph has an unique index from 1 to N, also each edge of the graph has an uniq

Bitwise And Queries

Bitwise And Queries Time limit: 1500 msMemory limit: 128 MB You are given QQ queries of the form a\ b\ xa b x. Count the number of values yy such that a \leq y \leq ba≤y≤b and x\ \& \ y = xx & y=x, where we denote by \&& the bitwise and op