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

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

     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("
    ");
    54 }
    55 int main() {
    56   work();
    57   return 0;
    58 }
  • 相关阅读:
    Reflector7.5.2.1(最新免费破解版)
    linux shell中变量的特殊处理
    linux中什么是shell?
    关于sql server中主键的一点研究
    根据数据库连接,登录操作系统的一个方法
    无图片取得圆角效果
    结对编程作业(java实现)
    第三章、android入门
    第七章:android应用
    javascript编辑excel并下载
  • 原文地址:https://www.cnblogs.com/NaVi-Awson/p/7615496.html
Copyright © 2020-2023  润新知