Codeforces 863DYet Another Array Queries Problem

来源:互联网 发布:美工在线培训 编辑:程序博客网 时间:2024/05/29 11:35

题意 :

一个序列支持两种操作
1. 将 l 到 r 向右移动一个单位
2. 将l 到 r 翻转

题解 :

首先注意到这个题目是一种离线的查询方式,另外又发现这个题最后的询问只有100个,这样的话我们不难想到这个题目应该有 O( 100 * 2e5 ) 的算法。考虑到每一次的操作只会影响在这个操作后面的操作,但是不会影响前面的操作,所以我们只需要逆序的将所有的操作模拟一遍就可以了。

#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;const int maxn = 2e5 + 10;struct node {    int type,l,r;}Q[maxn];int n,q,m;int a[maxn] = {0};int b[105] = {0};int solve (int x) {    for (int i = 1;i <= q; ++ i) {        if (Q[i].l <= x && Q[i].r >= x) {            if (Q[i].type == 1) {                x --;                if (x == Q[i].l - 1) x = Q[i].r;            }            else {                x = Q[i].l + Q[i].r - x;            }        }    }    return a[x];}int main () {    ios_base :: sync_with_stdio(false);    cin >> n >> q >> m;    for (int i = 1;i <= n; ++ i) {        cin >> a[i];    }    for (int i = q;i >= 1; -- i) {        cin >> Q[i].type >> Q[i].l >> Q[i].r;    }    for (int i = 1;i <= m; ++ i) {        int x;        cin >> x;        cout << solve (x) << ' ';    }    return 0;}