863D - Yet Another Array Queries Problem(思维)
原题连接:http://codeforces.com/problemset/problem/863/D
题意:对a数列有两种操作:
1 l r ,[l, r] 区间的数字滚动,即a[i+1]=a[i], a[l]=a[r]
2 l r ,[l, r] 区间的数字位置反转。
若干个操作之后输出a[b[i]].
思路:
由于是在操作结束后输出,且b[i]的个数不多(<=100),所以可以通过反推求出答案。
AC代码:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long LL;
const int MAXN = 2e5+;
struct Query {
int type;
int l,r;
}Q[MAXN];
int a[MAXN];
int n, q, m;
void print(int b)
{
for (int i = ;i <= q;i++) {
if (b >= Q[i].l&&b <= Q[i].r) {
if (Q[i].type == ) {
b--;
if (b < Q[i].l)
b = Q[i].r;
}
else
b = Q[i].r - (b - Q[i].l);
}
}
printf("%d", a[b]);
return;
}
int main() { scanf("%d %d %d", &n, &q, &m);
for (int i = ;i <= n;i++) {
scanf("%d", &a[i]);
}
for (int i = q;i >= ;i--) {
scanf("%d %d %d", &Q[i].type, &Q[i].l, &Q[i].r);
}
int b;
for (int i = ;i < m;i++) {
scanf("%d", &b);
if (i != ) printf(" ");
print(b);
}
printf("\n");
return ;
}
863D - Yet Another Array Queries Problem(思维)的更多相关文章
- [Codeforces 863D]Yet Another Array Queries Problem
Description You are given an array a of size n, and q queries to it. There are queries of two types: ...
- Yet Another Array Queries Problem CodeForces - 863D (暴力/思维)
You are given an array a of size n, and q queries to it. There are queries of two types: 1 li ri — p ...
- Codeforces 797E - Array Queries
E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds m ...
- lightoj Again Array Queries
1100 - Again Array Queries PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 ...
- codeforces 797 E. Array Queries【dp,暴力】
题目链接:codeforces 797 E. Array Queries 题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...
- AC日记——Array Queries codeforces 797e
797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...
- Light OJ-1082 - Array Queries,线段树区间查询最大值,哈哈,水过~~
...
- Light oj-1100 - Again Array Queries,又是这个题,上次那个题用的线段树,这题差点就陷坑里了,简单的抽屉原理加暴力就可以了,真是坑~~
1100 - Again Array Queries ...
- CF797E. Array Queries
a is an array of n positive integers, all of which are not greater than n. You have to process q que ...
随机推荐
- struts2默认action设置了却访问不到
1.错误原因 我的package中共有两个action,第一个是默认action,用于访问的action不存在时候的出错处理,第二个是通配符方式写的action,name采用*_*形式的全通配符.配置 ...
- PHP5和PHP7引用对比(笔记)
php5在引入引用计数后,使用了refcount_gc来记录次数,同时使用is_ref_gc来记录是否是引用类型. 例如 $a = 'hello'; //$a->zval1(type=IS_ST ...
- 【Linux-驱动】驱动策略----信号量
访问共享资源的代码区块叫“临界区”,临界区需要以某种互斥机制加以保护:自旋锁.信号量等.互斥访问:一个执行单元在访问共享资源的时候,其他的执行单元被禁止访问. 信号量:在Liunx中的信号量是一种睡眠 ...
- oracle跟SQL Server 2005 的区别
Oracle与Sql server的区别 一直搞不明白Oracle数据库和sql server的区别,今天我特意查资料把他们的区别整理出来 Oracle数据库:Oracle Database,又名 ...
- 剑指offer-二叉搜索树与双向链表-python
题目描述 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建任何新的结点,只能调整树中结点指针的指向.. # -*- coding:utf-8 -*- # class TreeN ...
- vscode学习(三)之如何修改打开终端的默认shell
实现 第一步:打开VSCode的设置(Preferences>User Settings) 第二步:搜索terminal.integrated.shell.osx 的 并把它的值改为你的zsh安 ...
- windows 桌面背景设置实例
应用SystemParametersInfo函数可以获取和设置数量众多的windows系统参数.这个小程序就是运用了SystemParametersInfo函数来设置桌面的墙纸背景,而且程序可以让我们 ...
- django基础篇06-ModelForm操作及验证
本文内容主要来自银角大王的博客 学习大纲: 一.ModelForm 二.Ajax - 原生(jQuery) - 伪Ajax操作 三.文件上传(预览) - Form提交 - Ajax文件上传 四. 图片 ...
- 流畅的Python (Fluent Python) —— 第一部分
Python 最好的品质之一是一致性. 魔术方法(magic method)是特殊方法的昵称.特殊方法也叫双下方法. 1.1 一摞Python风格的纸牌 import collections Card ...
- octave-bug - 报告 GNU Octave 中的 bug
SYNOPSIS 总览 octave-bug [-s subject] DESCRIPTION 描述 octave-bug 是一个 shell 脚本,用于以一种标准的格式撰写有关 Octave 的 b ...