[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:
- 1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal to old value of ax, and new value of ali becomes equal to old value of ari;
- 2 li ri — reverse the segment [li, ri].
There are m important indices in the array b1, b2, ..., bm. For each i such that 1 ≤ i ≤ m you have to output the number that will have index bi in the array after all queries are performed.
Input
The first line contains three integer numbers n, q and m (1 ≤ n, q ≤ 2·105, 1 ≤ m ≤ 100).
The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).
Then q lines follow. i-th of them contains three integer numbers ti, li, ri, where ti is the type of i-th query, and [li, ri] is the segment where this query is performed (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n).
The last line contains m integer numbers b1, b2, ..., bm (1 ≤ bi ≤ n) — important indices of the array.
Output
Print m numbers, i-th of which is equal to the number at index bi after all queries are done.
Sample Input
6 3 5
1 2 3 4 5 6
2 1 3
2 3 6
1 1 6
2 2 1 5 3
Sample Output
3 3 1 5 2
题解
官方给出的标签是数据结构...确实可以打个链表,但你发现$m<=100$,我们甚至暴力模拟都不会超时。
我们离线所有的操作,我们每读入一个询问,倒序操作模拟一遍就好了。
//It is made by Awson on 2017.9.30
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
using namespace std;
const int N = 2e5;
void read(int &x) {
char ch; bool flag = ;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || ); ch = getchar());
for (x = ; isdigit(ch); x = (x<<)+(x<<)+ch-, ch = getchar());
x *= -*flag;
} struct Query {
int id, l, r;
}query[N+];
int n, q, m, p;
int a[N+]; void work() {
read(n), read(q), read(m);
for (int i = ; i <= n; i++) read(a[i]);
for (int i = ; i <= q; i++)
read(query[i].id), read(query[i].l), read(query[i].r);
while (m--) {
scanf("%d", &p);
for (int i = q; i >= ; i--) {
if (query[i].l <= p && query[i].r >= p) {
if (query[i].id == ) {
if (query[i].l == p) p = query[i].r;
else p--;
}
else {
p = query[i].r-(p-query[i].l);
}
}
}
printf("%d ", a[p]);
}
printf("\n");
}
int main() {
work();
return ;
}
[Codeforces 863D]Yet Another Array Queries Problem的更多相关文章
- 863D - Yet Another Array Queries Problem(思维)
原题连接:http://codeforces.com/problemset/problem/863/D 题意:对a数列有两种操作: 1 l r ,[l, r] 区间的数字滚动,即a[i+1]=a[i] ...
- 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 ...
- Educational Codeforces Round 19 E. Array Queries(暴力)(DP)
传送门 题意 给出n个数,q个询问,每个询问有两个数p,k,询问p+k+a[p]操作几次后超过n 分析 分块处理,在k<sqrt(n)时,用dp,大于sqrt(n)用暴力 trick 代码 #i ...
- Codeforces 797E - Array Queries
E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds m ...
- 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 ...
- lightoj Again Array Queries
1100 - Again Array Queries PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 ...
- Codeforces 442C Artem and Array(stack+贪婪)
题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...
- Codeforces Round #504 D. Array Restoration
Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...
随机推荐
- 新事物学习---WebApp移动端手势Hammer
花落水流红,闲愁万种,无语怨东风. Hammer介绍 Hammer库是一个移动端手势库,移动端的手势操作(比如touch,tap,拖动,滑动等等)都可以用这个库,而我们不用关心,它的底层方案具体是怎么 ...
- 福州大学W班-alpha冲刺评分
作业链接 https://edu.cnblogs.com/campus/fzu/FZUSoftwareEngineering1715W/homework/1159 作业要求 1.前期准备 阅读学习&l ...
- 【Alpha】阶段总结报告
团队成员 陈家权 031502107 赖晓连 031502118 雷晶 031502119 林巧娜 031502125 庄加鑫 031502147 一.项目预期计划及现实进展 项目预期计划 现实进展 ...
- Beta冲刺-用户测试报告
一.项目概述 1.1项目名称 高校学生征信系统 1.2项目简介 此项目基于SSH框架,力图为学生提供征信服务和信用相关的借款和申请活动.其中以信用统计和管理为主,信用使用为辅,构建出一个集信用收集和使 ...
- 【Alpha】咸鱼冲刺日记第一天-黄紫仪
总汇链接 一,合照 emmmmm.自然是没有的. 二,项目燃尽图 emmmmm,事实上它还没有正式开始.所以依旧没有[突然觉得明天任务真重] 三,项目进展 emmmmm,我错了咸鱼了两天才突然反应过来 ...
- Alpha冲刺Day7
Alpha冲刺Day7 一:站立式会议 今日安排: 由林静和周静平共同完成企业风险分级展示这一模块的分级列表展示,该模块主要提供企业自查风险的条件查询功能 由黄腾飞和张梨贤共同完成企业风险分级展示的分 ...
- Flask 学习 四 数据库
class Role(db.Model): __tablename__='roles' id = db.Column(db.Integer,primary_key=True) name = db.Co ...
- HAOI 2012 高速公路
https://www.luogu.org/problem/show?pid=2221 题目描述 Y901高速公路是一条重要的交通纽带,政府部门建设初期的投入以及使用期间的养护费用都不低,因此政府在这 ...
- C++高效安全的运行时动态类型转换
关键字:static_cast,dynamic_cast,fast_dynamic_cast,VS 2015. OS:Window 10. C++类之间类型转换有:static_cast.dynami ...
- CNN中的padding
在使用TF搭建CNN的过程中,卷积的操作如下 convolution = tf.nn.conv2d(X, filters, strides=[1,2,2,1], padding="SAME& ...