[Codeforces 863D]Yet Another Array Queries Problem

本文介绍了一种通过模拟算法解决特定类型数组查询问题的方法。面对含有两类查询操作的数组,文章提出了一种简单直接的解决方案,即离线处理所有查询,并通过倒序模拟来高效获取指定索引处的元素值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

You are given an array a of size n, and q queries to it. There are queries of two types:

  • 1 liri — 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 liri — 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$,我们甚至暴力模拟都不会超时。

我们离线所有的操作,我们每读入一个询问,倒序操作模拟一遍就好了。

 1 //It is made by Awson on 2017.9.30
 2 #include <set>
 3 #include <map>
 4 #include <cmath>
 5 #include <ctime>
 6 #include <queue>
 7 #include <stack>
 8 #include <vector>
 9 #include <cstdio>
10 #include <string>
11 #include <cstdlib>
12 #include <cstring>
13 #include <iostream>
14 #include <algorithm>
15 #define LL long long
16 #define Min(a, b) ((a) < (b) ? (a) : (b))
17 #define Max(a, b) ((a) > (b) ? (a) : (b))
18 using namespace std;
19 const int N = 2e5;
20 void read(int &x) {
21   char ch; bool flag = 0;
22   for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
23   for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
24   x *= 1-2*flag;
25 }
26 
27 struct Query {
28   int id, l, r;
29 }query[N+5];
30 int n, q, m, p;
31 int a[N+5];
32 
33 void work() {
34   read(n), read(q), read(m);
35   for (int i = 1; i <= n; i++) read(a[i]);
36   for (int i = 1; i <= q; i++)
37     read(query[i].id), read(query[i].l), read(query[i].r);
38   while (m--) {
39     scanf("%d", &p);
40     for (int i = q; i >= 1; i--) {
41       if (query[i].l <= p && query[i].r >= p) {
42     if (query[i].id == 1) {
43       if (query[i].l == p) p = query[i].r;
44       else p--;
45     }
46     else {
47       p = query[i].r-(p-query[i].l);
48     }
49       }
50     }
51     printf("%d ", a[p]);
52   }
53   printf("\n");
54 }
55 int main() {
56   work();
57   return 0;
58 }

 

转载于:https://www.cnblogs.com/NaVi-Awson/p/7615496.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值