码迷,mamicode.com
首页 > 其他好文 > 详细

863D - Yet Another Array Queries Problem(思维)

时间:2017-09-23 23:18:25      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:cst   printf   class   namespace   个数   long   i++   oid   pac   

原题连接:http://codeforces.com/problemset/problem/863/D

 

题意:对a数列有两种操作:

1 l r ,[l, r] 区间的数字滚动,即a[i+1]=a[i], a[l]=a[r]

2 l r ,[l, r] 区间的数字位置反转。

若干个操作之后输出a[b[i]].

 

思路:

由于是在操作结束后输出,且b[i]的个数不多(<=100),所以可以通过反推求出答案。

 

AC代码:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 typedef long long LL;
 6 const int MAXN = 2e5+10;    
 7 struct Query {
 8     int type;
 9     int l,r;
10 }Q[MAXN];
11 int a[MAXN];    
12 int n, q, m;
13 void print(int b)
14 {
15     for (int i = 1;i <= q;i++) {
16         if (b >= Q[i].l&&b <= Q[i].r) {
17             if (Q[i].type == 1) {
18                 b--;
19                 if (b < Q[i].l)
20                     b = Q[i].r;
21             }
22             else 
23                 b = Q[i].r - (b - Q[i].l);
24         }
25     }
26     printf("%d", a[b]);
27     return;
28 }
29 int main() {
30 
31     scanf("%d %d %d", &n, &q, &m);
32     for (int i = 1;i <= n;i++) {
33         scanf("%d", &a[i]);
34     }
35     for (int i = q;i >= 1;i--) {
36         scanf("%d %d %d", &Q[i].type, &Q[i].l, &Q[i].r);
37     }
38     int b;
39     for (int i = 0;i < m;i++) {
40         scanf("%d", &b);
41         if (i != 0) printf(" ");
42         print(b);
43     }
44     printf("\n");
45     return 0;
46 }

 

863D - Yet Another Array Queries Problem(思维)

标签:cst   printf   class   namespace   个数   long   i++   oid   pac   

原文地址:http://www.cnblogs.com/MasterSpark/p/7583236.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!