Educational Codeforces Round 29 - D. Yet Another Array Queries Problem

D. Yet Another Array Queries Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 b1b2, ..., 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 nq and m (1 ≤ n, q ≤ 2·1051 ≤ m ≤ 100). 

The second line contains n integer numbers a1a2, ..., an (1 ≤ ai ≤ 109). 

Then q lines follow. i-th of them contains three integer numbers tiliri, where ti is the type of i-th query, and [li, ri] is the segment where this query is performed (1 ≤ ti ≤ 21 ≤ li ≤ ri ≤ n). 

The last line contains m integer numbers b1b2, ..., 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.

Example
input
6 3 5
1 2 3 4 5 6
2 1 3
2 3 6
1 1 6
2 2 1 5 3
output
3 3 1 5 2 

题意:

给你n个数a[],给你q个操作,1操作,让l到r里的数都向前转一圈。l变成r,l+1变成l,l+2变成l+1。r变成r-1。如此变化。

2操作,反转l,r里的所有数。

问你m个数b[],求出变化后的a[bi]。

POINT:

虽然这题一开始很容易想到线段树,但其实一点关系都没有。一开始会想到按照q操作来巧妙的求出a[],但其实想不出。

因为m<=100,那么我们就来根据要求的a[bi],来推出他原来是什么a[ans]。

保存这q个操作,对每一个bi进行倒推,每次操作如果影响到了bi,就倒着模拟一次。因为每次操作只影响l到r的范围。所以bi在l-r之外的话就不用管。当然,这个bi是根据倒推的进程在变化的。

时间复杂度为m*q。


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include<algorithm>
using namespace std;
#define LL long long
const int maxn = 200000+100;
int a[maxn];
int n,q,m;
int ans[111];

struct node
{
    int kind;
    int l,r;
}opt[maxn];
void doit(int temp,int now)
{
    for(int i=q;i>=1;i--){
        int k=opt[i].kind;
        int l=opt[i].l;
        int r=opt[i].r;
        if(k==1){
            if(l<=temp&&temp<=r){
                temp--;
                if(temp==l-1)
                    temp=r;
            }
        }
        else{
            if(l<=temp&&temp<=r){
                int c=temp-l;
                temp=r-c;
            }
        }
    }
    printf("%d",a[temp]);
}
int main()
{
    scanf("%d %d %d",&n,&q,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    memset(ans,0,sizeof ans);
    for(int i=1;i<=q;i++){
        scanf("%d %d %d",&opt[i].kind,&opt[i].l,&opt[i].r);
    }
    for(int i=1;i<=m;i++){
        if(i-1) printf(" ");
        int a;
        scanf("%d",&a);
        doit(a,a);
    }
    printf("\n");

}



根据提供的引用内容,Codeforces Round 511 (Div. 1)是一个比赛的名称。然而,引用内容中没有提供与这个比赛相关的具体信息或问题。因此,我无法回答关于Codeforces Round 511 (Div. 1)的问题。如果您有关于这个比赛的具体问题,请提供更多的信息,我将尽力回答。 #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces Round 867 (Div. 3)(A题到E题)](https://blog.csdn.net/wdgkd/article/details/130370975)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值